HiveBrain v1.2.0
Get Started
← Back to all entries
principlecsharpCritical

WaitAll vs WhenAll

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
whenallwaitallstackoverflow

Problem

What is the difference between Task.WaitAll() and Task.WhenAll() from the Async CTP?
Can you provide some sample code to illustrate the different use cases?

Solution

Task.WaitAll blocks the current thread until everything has completed.

Task.WhenAll returns a task which represents the action of waiting until everything has completed.

That means that from an async method, you can use:

await Task.WhenAll(tasks);


... which means your method will continue when everything's completed, but you won't tie up a thread to just hang around until that time.

Code Snippets

await Task.WhenAll(tasks);

Context

Stack Overflow Q#6123406, score: 773

Revisions (0)

No revisions yet.