Parallel的使用

           Action<int, int> ReportProcess //返回数据,刷新进度
Exception exception = null; object objLock = new object(); Parallel.For(0, counts, new ParallelOptions() { MaxDegreeOfParallelism = 10 }, (i, loopState) => { if (exception != null) return; lock (objLock) { try { if (isCancel)//是否结束 loopState.Break();
//处理 Process
++;if (ReportProcess != null) ReportProcess(data.Count, Process); } catch (Exception ex) { data[i].error = ex.Message; exception = ex; } } }); if (exception != null) throw exception;

 

posted @ 2018-11-22 14:56  世人皆萌  阅读(680)  评论(0编辑  收藏  举报