.NET 4 等效于 Task.WhenAll() [英] .NET 4 equivalent of Task.WhenAll()
问题描述
在 .NET 4 中,是否有任何功能等同于 .NET 4.5 的 System.Threading.Tasks.Task.WhenAll()?
In .NET 4, is there any functional equivalent to .NET 4.5's System.Threading.Tasks.Task.WhenAll()?
目标是将多个异步任务合并为一个,并在其所有组成任务完成后完成.
The goal is to wrap up multiple async tasks into a single one that is completed when all of its constituent tasks are done.
推荐答案
我认为 .Net 4.0 内置的最接近的东西是 ContinueWhenAll()
.您可以使 continuationAction
成为一个简单的 tasks =>任务
并使用返回的Task
.
I think the closest thing built-in in .Net 4.0 is ContinueWhenAll()
. You can make the continuationAction
a simple tasks => tasks
and use the returned Task
.
出于性能原因,您可能希望将其与 TaskContinuationOptions.ExecuteSynchronously
一起使用.
For performance reasons, you might want to use it with TaskContinuationOptions.ExecuteSynchronously
.
这篇关于.NET 4 等效于 Task.WhenAll()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!