4

According to MSDN Task.WaitAll throughs the AggregateException as soon as an exception was thrown during the execution of at least one of the Task instances. I need wait for all the tasks are finished handling each thrown exception. So do I need make something like:

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

or is some more rational way?

4

1 回答 1

6

The docs don't say that WaitAll returns as soon as one exception occurs. The opposite is true: it always waits for all tasks to complete.

Waits for all of the provided Task objects to complete execution.

This is already the behavior that you want.

于 2013-09-17T14:48:41.270 回答