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)?
Asked
Active
Viewed 221 times
1 Answers
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