Код: Выделить всё
///
/// Creates a task that will complete when all of the supplied tasks have completed.
/// This task contains the exceptions of the faulted tasks in their positional order
/// (not chronological order).
///
public static Task WhenAll_OrderedExceptions(params Task[] tasks);
Код: Выделить всё
async Task DoAsync(string title, int delay)
{
await Task.Delay(delay);
throw new Exception(title);
}
Task t1 = DoAsync("A", 200);
Task t2 = DoAsync("B", 100);
try
{
WhenAll_OrderedExceptions(t1, t2).Wait();
}
catch (AggregateException aex)
{
Console.Write($"Error message: {aex.Message}");
}
< /code>
Желательный вывод: < /p>
Error message: One or more errors occurred. (A) (B)
< /code>
Нежелательный вывод: < /p>
Error message: One or more errors occurred. (B) (A)
Подробнее здесь: https://stackoverflow.com/questions/793 ... exceptions