What is the difference between:
foreach(Task task in someTasks)
{
task.Wait();
}
and
Task.WaitAll(sometasks);
In essence, looking from the end result perspective, they should be doing the same thing?
What is the difference between:
foreach(Task task in someTasks)
{
task.Wait();
}
and
Task.WaitAll(sometasks);
In essence, looking from the end result perspective, they should be doing the same thing?
The difference is in the exception handling. If task.Wait();
throws, the foreach
loop is exited. WaitAll
will catch all exceptions and throw an AggregateException
containing them.
See also: Task.WaitAll and Exceptions