Task.WaitAll, how to find the tasks causing AggregateException

c#, task-parallel-library

Solution

You still have the list of `Tasks`, and each `Task` has an `Exception` property. Using that you can figure out which exceptions belong with which `Task`.

But, if you can, it'd be better to use `Task.WhenAll` or `TaskFactory.ContinueWhenAll` than do a blocking Wait.

Problem

Let's say that I got the following code: ``` var tasks = BuildTaskList(); try { Task.WaitAll(tasks.ToArray()); } catch (AggregateException exception) { } ``` How do I know which task threw which of the exceptions in `exception.InnerExceptions`?

Original source