简体   繁体   English

等待异常处理完成所有任务

[英]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. 根据MSDN Task.WaitAll在执行至少一个Task实例期间抛出异常时立即通过AggregateException。 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? 或者是一些更理性的方式?

The docs don't say that WaitAll returns as soon as one exception occurs. 一旦发生一个异常,文档就不会说WaitAll返回。 The opposite is true: it always waits for all tasks to complete. 反之亦然:它总是等待所有任务完成。

Waits for all of the provided Task objects to complete execution. 等待所有提供的Task对象完成执行。

This is already the behavior that you want. 这已经是您想要的行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM