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

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

问题描述

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

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.

推荐答案

来自 MSDN:

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

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

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

如果没有任务发生故障并且没有任务被取消,则结果任务将以 RanToCompletion 状态结束.的结果返回的任务将被设置为一个包含所有所提供任务的结果按照提供的顺序(例如,如果输入任务数组包含 t1、t2、t3,则输出任务的结果将返回一个 TResult[],其中 arr[0] == t1.Result, arr1 ==t2.Result, 和 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天全站免登陆