3 ms·
> The runtime will generally schedule IO bound tasks to run on the threadpool. Well, that's not correct. Unless you explicitly call Task.Run or Task.Start (or
by pow_pp_-1_v 6y ago
> The runtime will generally schedule IO bound tasks to run on the threadpool.
Well, that's not correct. Unless you explicitly call Task.Run or Task.Start (or other similar methods) no new thread is created. The compiler generated state machines don't require the threading mechanism to work. In fact the overhead for async/await is mostly the extra code generated for the state machine and error handling. At runtime, there's no thread switching overhead.
- GordonS 6y agoYes, I meant using Task.Run; I was simplifying, as I'd assumed (wrongly) you were familiar with async/await from another language. Otherwise, from memory, the runtime spec doesn't actually guarantee that await won't run on a threadpool thread - it will under certain circumstances. And then there are further nuances if there is a synchronisation context and ConfigureAwait(false) is used, as the continuation will be scheduled on a threadpool thread.