2

If I have an array of tasks, Task[]. How can I write a continuation that only runs when one or more tasks in the array fails(or is cancelled)?

Erik Z
  • 4,660
  • 6
  • 47
  • 74

1 Answers1

0

I think you should look at the continuation options that you can specify when you set the continuation for a Task.

Task<int> [] tasks = new Task<int>[5];
// Add tasks...

foreach (var task in tasks)
{
    task.ContinueWith(a => a.Id, TaskContinuationOptions.OnlyOnCanceled);
}
Task.WaitAny(tasks, new CancellationToken());
Slugart
  • 4,535
  • 24
  • 32