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;