当前位置: 首页 > 工具软件 > Parallel > 使用案例 >

Parallel的使用

邹祺
2023-12-01
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;

 

转载于:https://www.cnblogs.com/shuaimeng/p/10001065.html

 类似资料: