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.
WhenAll(IEnumerable<Task>) Creates a task that will complete when all of the Task objects in an enumerable collection have completed. WhenAll(Task[]) Creates a task that will complete when all of the Task objects in an array have completed.
WhenAll returns control after all tasks are completed, while WhenAny returns control as soon as a single task is completed.
WhenAll creates a task that will complete when all of the supplied tasks have been completed. It's pretty straightforward what this method does, it simply receives a list of Tasks and returns a Task when all of the received Tasks completes.
WhenAll does not create a new thread. A "task" does not necessarily imply a thread; there are two types of tasks: "event" tasks (e.g., TaskCompletionSource ) and "code" tasks (e.g., Task. Run ). WhenAll is an event-style task, so it does not represent code.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With