Asynchronous Operations · TL;DR

1 min read
Mid-level11 min read
Rapid overview

TL;DR

An asynchronous operation is one you start now and whose result arrives later, without the caller having to wait on a thread in the meantime. In .NET it is represented by a Task / Task<T> (or ValueTask): a promise of a future result. Most real asynchronous operations are I/O (network, database, disk, timers): once the request is handed to the operating system, no thread is used while waiting; the OS signals completion and a thread-pool thread runs the rest of your code. Pausing asynchronously is what await does: if the awaited task is not finished, the method suspends, saving its local state in a heap object, and returns to its caller immediately, freeing the thread to do other work. When the task completes, the method resumes from the same point, possibly on a different thread. Compare Thread.Sleep(1000) (the thread is blocked and wasted for a second) with await Task.Delay(1000) (no thread is used for that second). This is what lets a server handle thousands of concurrent requests with a few dozen threads, and a UI stay responsive. The deeper compiler and SynchronizationContext details are in the Core C# note "Async Await Deep Dive".

See also