SerG
SerG

Reputation: 1340

Waiting for finishing of all tasks with exception handling

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?

Upvotes: 4

Views: 674

Answers (1)

usr
usr

Reputation: 171178

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.

Upvotes: 6

Related Questions