In continuation of this question.
So let's have a few asynchronous methods.
async Task DoFoo() { ... } async Task DoBar() { ... } async Task DoBaz() { ... } which in another asynchronous method
async Task DoJob() { //TODO: perform DoFoo, DoBar and DoBaz in parallel } required to run in parallel.
If you follow the answers in the above question, then to parallel the execution of several asynchronous methods, you need to call them like this:
async Task DoJob() { Task t1 = DoFoo(); Task t2 = DoBar(); Task t3 = DoBaz(); await Task.WhenAll(t1, t2, t3); } In the TaskScheduler documentation, however, I read:
If you’re not a problem, you’ll have to do it. However, tasks that have been created are differently, but differently. It is a queuing task. It can be a child. For this is what it looks like it’s ready for more work.
With regard to the situation, if I understand correctly, tasks t1, t2, t3 are not root-level tasks (because they are nested in a DoJob ), and therefore, starting, they do not end up in a global queue that is processed by multiple pool threads, but - in the local queue of any one particular thread.
It turns out that the multithreaded execution of several asynchronous methods does not provide such a method?
Yes, work stealing can happen, but is it worth Task.Run(...) on it, or to achieve concurrency, it is better to wrap all methods in Task.Run(...) (which will send tasks to be executed on a thread pool, i.e., apparently, global queue )
async Task DoJob() { Task t1 = Task.Run(DoFoo); Task t2 = Task.Run(DoBar); Task t3 = Task.Run(DoBaz); await Task.WhenAll(t1, t2, t3); } ?