c# - Task.WhenAll 结果排序

标签 c# asynchronous concurrency parallel-processing task-parallel-library

我从here了解到Task.Whenall 的任务执行顺序不是确定性的,但我找不到有关结果顺序的任何信息。

结果集合是否会按照输入中任务的排序顺序包含结果,或者结果可以按任何顺序包含?

从我所做的测试来看,它似乎保留了订单,但我需要确认。

最佳答案

来自 MSDN :

Task.WhenAll<TResult>(IEnumerable<Task<TResult>>)

这是四个重载中唯一包含此语句的重载:

If none of the tasks faulted and none of the tasks were canceled, the resulting task will end in the RanToCompletion state. The Result of the returned task will be set to an array containing all of the results of the supplied tasks in the same order as they were provided (e.g. if the input tasks array contained t1, t2, t3, the output task's Result will return an TResult[] where arr[0] == t1.Result, arr1 == t2.Result, and arr[2] == t3.Result).

关于c# - Task.WhenAll 结果排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23175611/

相关文章:

c# - 分配 C# 事件处理程序的差异?

mysql - MySQL Nodejs并发访问多表

scala - 如何保证Actor的响应时间?

外部共享资源(智能卡)的 Java 并发模式

c# - 如何在 C# 中从客户端的服务器获取构造函数?

c# - MVC + WCF + TDD 或 DDD 架构

c# - Silverlight打印抗锯齿

javascript - 是否可以在 jQuery.each() 内部使用同步 promise sleep ?

javascript - 使用 onload 事件加载异步 javascript 的缓存问题

javascript - 如何使异步事件处理程序按特定顺序工作?