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.
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.
In .NET Framework 4.0 WhenAll and WhenAny can be used with installed AsyncCTP in case of Visual Studio 2010 or Async Targeting Pack in case of Visual Studio 2012.
The WhenAll and WhenAny methods are then offered on the TaskEx type.
I think the closest thing built-in in .Net 4.0 is
ContinueWhenAll()
. You can make thecontinuationAction
a simpletasks => tasks
and use the returnedTask
.For performance reasons, you might want to use it with
TaskContinuationOptions.ExecuteSynchronously
.Try waiting on
Task.WaitAll()
in another Task. Use the LINQ extension methodToArray
to convert fromIEnumerable<Task>
toTask[]
.