Example #1
0
 private async Task StartCommandAsync()
 {
     if (Cancel != null && TasksContinues.Count != 0)
     {
         await StopCommand.ExecuteAsync(null);
     }
     Cancel = new CancellationTokenSource();
     for (int i = 0; i < CoresForWorking; i++)
     {
         //var task = WorkTask(Cancel.Token);
         //try/catch instead - using continuewith OnlyOnCancelled
         var taskContinue = WorkTask(Cancel.Token).ContinueWith(t => TasksContinues.Clear(), TaskContinuationOptions.OnlyOnCanceled);
         TasksContinues.Add(taskContinue);
     }
     await Task.WhenAll(TasksContinues).ConfigureAwait(false);
 }