Пример #1
0
        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); });
            });
        }
Пример #2
0
        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); });
            });
        }
Пример #3
0
 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); });
 }
Пример #4
0
 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); });
 }