c# - 任务WhenAll异常处理

标签 c#

我希望在某些任务可能失败的情况下使用 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/

相关文章:

c# - WPF DragDropEffects 在 Drop 事件中未正确设置

C# 从 list<decimal> 到 double 数组的转换

c# - MySql.Data 'new Thread' 与 ThreadPool : using ThreadPool creates a deadlock

c# - 为什么我的类(class)突然有一个 'designer' ?

C# 依赖注入(inject)示例

c# - guid 可以是一个好的分区键吗?

c# - 一小时后身份从不记名 token 中消失

c# - 复选框数据绑定(bind)默认值 null

c# - Entity Framework 、SQLite 和延迟加载

c# - 在 Unity 中使用 GestureRecogniser 双击全息镜头