Waiting for completion of all tasks with exception handling

According to the MSDN Task.WaitAll via AggregateException, as soon as an exception occurs during the execution of at least one instance task. I need to wait until all tasks are processed with every exception thrown. So I need to do something like:

while (true) { try { Task.WaitAll(tasks); break; //only if no exception is occured } catch (AggregateException aex) { //exceptions handling... } } 

or is it a more rational way?

+4
source share
1 answer

The docs don't say WaitAll returns as soon as one exception is thrown. The opposite is true: he is always waiting for all tasks to be completed.

Expects all provided task objects to complete.

This is the behavior you want.

+6
source

Source: https://habr.com/ru/post/1502634/


All Articles