Task.WhenAll结果排序 [英] Task.WhenAll result ordering

查看:198
本文介绍了Task.WhenAll结果排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I understand from here that the task execution order for Task.Whenall is not deterministic but I cannot find any information about result order.

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

Will the results collection contain the results in the order in which the tasks where ordered in the input or the results can be in any order?

从我做的测试,似乎保持顺序,但我需要确认。

From the tests that I did, it seems to keep the order but I need a confirmation.

推荐答案

p>从 MSDN

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

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

This is the only overload of the four which contains this statement:


任务故障,并且没有任何任务被取消,
生成的任务将在RanToCompletion状态结束。
的结果返回的任务将被设置为一个数组,该数组包含所提供任务的所有
结果按照提供的顺序
(例如如果输入任务数组包含t1,t2,t3,输出任务的
Result将返回一个TResult [],其中arr [0] == t1.Result,arr 1 ==
t2.Result,and arr [2] == t3.Result)。

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).

这篇关于Task.WhenAll结果排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆