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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With