private void RunForEachList <T>(IEnumerable <T> source, Action <T> action) { IList <T> list = source as IList <T>; int count = list.Count; if (count != 0) { int num = _threadCount; if (num > count) { num = count; } InitBeforeRun(num); int num2 = 0; int[] array = CalculateThreadsIterations(count, num); try { ForEachListParams <T> forEachListParams = default(ForEachListParams <T>); for (int i = 0; i < array.Length; i++) { forEachListParams.Action = action; forEachListParams.List = list; forEachListParams.Begin = num2; forEachListParams.End = num2 + array[i]; StartThread(ForEachListInThread <T>, forEachListParams); num2 += array[i]; } } catch (Exception) { EndWork(); throw; } } }
private void ForEachListInThread <T>(object param) { ForEachListParams <T> forEachListParams = (ForEachListParams <T>)param; IList <T> list = forEachListParams.List; try { do { for (int i = forEachListParams.Begin; i < forEachListParams.End; i++) { if (Canceling) { break; } forEachListParams.Action(list[i]); } if (!_enableInfiniteRepeat) { break; } _barrierForReps.SignalAndWait(); }while (!Canceling); } catch (Exception) { Cancel(); if (_enableInfiniteRepeat) { _barrierForReps.RemoveParticipant(); } throw; } finally { EndThread(); } }