我希望在某些任务可能失败的情况下使用 Task.WhenAll,但我仍然需要其余已完成任务的结果数据。
根据 MSDN ,
If any of the supplied tasks completes in a faulted state, the returned task will also complete in a Faulted state, where its exceptions will contain the aggregation of the set of unwrapped exceptions from each of the supplied tasks.
但是,它没有说明的是 Task.WhenAll 是否仍会等待其余任务在该实例中完成。任何人都可以就此问题提供任何说明吗?
最佳答案
正如文档所说:
Creates a task that will complete when all of the Task objects in an enumerable collection have completed.
因此它将等待所有任务完成,无论是否有任何任务已经抛出异常或已被取消。然后它将聚合可能的取消和异常并定义其状态。给定任务的结果将在原始任务中,以及异常和取消。
关于c# - 任务WhenAll异常处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52675789/