I was reading an article by @stephen-cleary around async/await. He mentioned below code
public async Task DoOperationsConcurrentlyAsync()
{
Task[] tasks = new Task[3];
tasks[0] = DoOperation0Async();
tasks[1] = DoOperation1Async();
tasks[2] = DoOperation2Async();
// At this point, all three tasks are running at the same time.
// Now, we await them all.
await Task.WhenAll(tasks);
}
He mentions the tasks are already started when the methods are called (e.g DoOperation0Async()). In which thread does these methods gets run in? Do all methods that return a Task run in a different thread (or get queued up in the threadpool).
OR do they all run synchronously? If they run synchronously, why use Task.WhenAll() ? Why not just await each method that returns a Task?
public async Task DoOperationsConcurrentlyAsync()
{
await DoOperation0Async();
await DoOperation1Async();
await DoOperation2Async();
}