I saw that everyone uses Task.WhenAll
like in case 1. Can I just return Task
which Task.WhenAll
returns inside case 2?
Additional questions:
- Is case 2 will be executed sync or not?
- If i'll call
MethodAsync()
inside async method and await it, will I have 3 opened threads (main thread,MethodAsync
thread,Task.WhenAll()
thread). Will one thread wait next thread for completition? - Which one case is better to use according to performance?
// case 1
public async Task MethodAsync()
{
await Task.WhenAll(...);
}
// case 2
public Task MethodAsync()
{
return Task.WhenAll(...);
}