使用Parallel.For方法替代基础的for循环,基础代码如下
Parallel.For(0, recordDT.Rows.Count, new ParallelOptions(), (x) => { recordDT.Rows[x] ......code }
如果在循环内需要使用到List等原生集合序列元素,请替代为:ConcurrentStack,否则List会缺失项目。
ConcurrentStack<string> strList = new ConcurrentStack<string>();