It's hard for me the fathom the benefit of offloading asynchronous work to Task.Run(). there have been many questions about async work being offloaded to a Task before, but I have never seen, what is for me the biggest mystery, being addressed.
consider two options:
- option1:
var t1= Task.Run( async() => { await CPUBoundWorkAsync(); });
- option2:
var t2= Task.Run( () => { CPUBoundWork(); });
With the 2nd option, the work is being offloaded to a separate thread, thus asynchronicity is "achieved", and the main thread can get back to whatever it's needed for. With the 1st option, the Async method is used and the delegate is expressed as Async. Both options should yield indistinguishable result in terms of not blocking the main thread, and having the CPU bound work finish at the same time. Is there a benefit from using the Async method in Task.Run ? it seems to me this is essentially letting the work that is already being ran asynchronously (on a different non blocking thread), to also run itself asynchronously. Can the the thread pool or whatever manages those task threads read into this? and then perhaps give that awaiting thread some other work to do ? if this is the case I haven't seen it mentioned in any expert blog post, or relevant page on the internet.