Difference in Task.WaitAll(result1, result2) and await result1; await result2;

65 Views Asked by At

We had a test case which had earlier below snippet written but the test case was failing due to race condition.

Task.WaitAll(result1, result2);

But when it changed to below it started working fine.

await result1; await result2;

Note: also we marked Test case as Async too but I don't think it makes any difference since I checked all test run async alphabetically anyway by Microsoft Unit Test framework.

1

There are 1 best solutions below

0
Shahrooz Taheri On

Task.WaitAll(result1, result2); is Blocking Call. it means that your current thread is blocked until your task is Done.

await is a non-blocking call: it means that your current Thread will not blocked.

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/await

multiple awaits vs Task.WaitAll - equivalent?