3 ms·
async doesn't use threads. Async is a goto state machine. While the IO is set as blocked at the operating system level, it does something else. Then when it's
by UK-AL 11y ago
async doesn't use threads.
Async is a goto state machine. While the IO is set as blocked at the operating system level, it does something else. Then when it's unblocked, it jumps back.
- guiomie 11y agoI'm still having a hard time with async. I see lot's of async code using Tasks, pretty much 99% of the time. Wouldn't this make async code using threads anyway?
- UK-AL 11y agoA task may or may not be run on another thread. It just represents a unit of work with a potential result. It can be confusing because Task objects original main use was running stuff on background worker threads. That is no longer the case. Note, you can use async and threads. But a lot of code using async and task are NOT using threads.
- edgyswingset 11y agoAsync code, down in the "guts" of the system, will borrow user-level and OS-level threads, so while it's correct that it does use threads, it won't spawn off new ones. Spawning off a new thread ultimately wouldn't accomplish much (after all, why not have IIS just use a new one?). I like to think of it as utilizing the operating system more efficiently. I/O on a system is asynchronous by default. Async code will essentially delegate work so the OS can do what it does best!