public static void For(int fromInclusive, int toExclusive, int threadPerRequest, ParallelActionWithState <int> action) { var cts = new CancellationTokenSource(); var options = CreateParallelOptions(threadPerRequest, cts); RunWithCatch(() => { Parallel.For(fromInclusive, toExclusive, options, (i, pls) => { action(i, cts, pls); }); }); }
public static void ForEach <T>(IEnumerable <T> list, int threadPerRequest, ParallelActionWithState <T> action) { var cts = new CancellationTokenSource(); var options = CreateParallelOptions(threadPerRequest, cts); RunWithCatch(() => { Parallel.ForEach(list, options, (obj, pls) => { action(obj, cts, pls); }); }); }
public static void For <T>(T[] array, int threadPerRequest, ParallelActionWithState <T> action) { For(0, array.Length, threadPerRequest, delegate(int i, CancellationTokenSource cts, ParallelLoopState pls) { action(array[i], cts, pls); }); }
public static void For <T>(IList <T> list, int threadPerRequest, ParallelActionWithState <T> action) { For(0, list.Count, threadPerRequest, delegate(int i, CancellationTokenSource cts, ParallelLoopState pls) { action(list[i], cts, pls); }); }