DEV Community

Discussion on: How YOU can make your .NET programs more responsive with async/await in .NET Core, C# and VS Code

Collapse
 
siamcr7 profile image
Jamil Siam

Just to clarify, "Task.WaitAll(...)" is essentially same as "await Task.WhenAll(...)". Please correct me if I am missing something.

If I am correct in my above statement, then shouldn't latter be the best approach to wait for all the tasks to complete?

Collapse
 
softchris profile image
Chris Noring

WaitAll and WhenAll is very different. WaitAll blocks the code on that line. WhenAll returns directly with a Task.. As for await Task.WhenAll(), yes you can do that... As for one approach is better than another, not sure tbh.. I do know that when I get a task back I have the capability check it's state, cancel it and so on.. With that said, I suppose WhenAll gives us more fine-grained control to affect all three Tasks like cancel all, cancel one etc... With WaitAll I'm stuck at that line so it might be tricky to do anything but just wait. So if we ar talking about more fine-grained control I lean on agreeing with you.