我从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/