Esempio n. 1
0
 /// <summary>
 /// Calls Parallel.ForEach() with appropriate ParallelOptions and exception handling.
 /// </summary>
 public static ParallelLoopResult ParallelForEach <TSource>(this MauiAsyncTask asyncTask, IEnumerable <TSource> source, Action <TSource> body)
 {
     return(Parallel.ForEach(source, ParallelOptions(asyncTask),
                             s =>
     {
         try
         {
             body(s);
         }
         catch (Exception exc)
         {
             asyncTask.LogCodedError("MAUI0000", exc.ToString());
             asyncTask.Cancel();
         }
     }));
 }
Esempio n. 2
0
 /// <summary>
 /// Calls Task.Run<T>() with a proper CancellationToken.
 /// </summary>
 public static Task <TSource> RunTask <TSource>(this MauiAsyncTask asyncTask, Func <TSource> body) =>
 Task.Run(body, asyncTask.CancellationToken);
Esempio n. 3
0
 /// <summary>
 /// Calls Task.Run() with a proper CancellationToken.
 /// </summary>
 public static Task RunTask(this MauiAsyncTask asyncTask, Action body) =>
 Task.Run(body, asyncTask.CancellationToken);
Esempio n. 4
0
 static ParallelOptions ParallelOptions(MauiAsyncTask asyncTask) => new ParallelOptions
 {
     CancellationToken = asyncTask.CancellationToken,
     TaskScheduler     = TaskScheduler.Default,
 };