Exemple #1
0
        public static void ForEach <T>(IEnumerable <T> list, int threadPerRequest,
                                       ParallelActionWithCancel <T> action)
        {
            var cts     = new CancellationTokenSource();
            var options = CreateParallelOptions(threadPerRequest, cts);

            RunWithCatch(() =>
            {
                Parallel.ForEach(list, options, obj => { action(obj, cts); });
            });
        }
Exemple #2
0
        public static void For(int fromInclusive, int toExclusive, int threadPerRequest,
                               ParallelActionWithCancel <int> action)
        {
            var cts     = new CancellationTokenSource();
            var options = CreateParallelOptions(threadPerRequest, cts);

            RunWithCatch(() =>
            {
                Parallel.For(fromInclusive, toExclusive, options, i => { action(i, cts); });
            });
        }
Exemple #3
0
 public static void For <T>(T[] array, int threadPerRequest, ParallelActionWithCancel <T> action)
 {
     For(0, array.Length, threadPerRequest, delegate(int i, CancellationTokenSource cts) { action(array[i], cts); });
 }
Exemple #4
0
 public static void For <T>(IList <T> list, int threadPerRequest, ParallelActionWithCancel <T> action)
 {
     For(0, list.Count, threadPerRequest, delegate(int i, CancellationTokenSource cts) { action(list[i], cts); });
 }