Tuesday, February 18, 2014

Task Parallel Library: WaitAll vs WhenAll

While implementing some async voodoo I noticed that there were 2 very similar methods on the Task class: WaitAll and WhenAll.

So what’s the difference between the 2?

  • Task.WhenAll creates a task that will complete when all of the supplied tasks have completed. It will not block the current execution but allows you to await the tasks for completion.
  • Task.WaitAll will wait for all of the provided Task objects to complete execution.This will block the current execution until all tasks are done.

So if you are inside an async method, you probably want to use Task.WhenAll and use await to get the results.

No comments: