Everything You (Don’t) Want to Know About Async and Await in C#
summary
Deep dive into how C# rewrites async/await into a compiler-generated state machine: demos show Task.Delay(500/1000ms), printed thread IDs, and live polls (≈41–48 votes) that reveal a console app has no SynchronizationContext so continuations go to the thread pool (configureAwait has no effect there). Covers exception surfacing via GetResult, three task terminal states, cooperative cancellation patterns, async streams with cancellation, pitfalls of async void and ValueTask, and a working custom awaiter for Control.Dispatcher to marshal back to UI.
AI-written summary · about
chapters (12)
- 0:00Introduction and motivation
- 2:20Async/await fundamentals
- 5:05Control flow in async methods
- 12:00Task combinators and parallelism
- 14:40Under the hood: The state machine
- 23:40Task states and exception handling
- 27:20Cooperative cancellation
- 31:50Advanced task patterns
- 40:20Custom awaitables
- 50:40Async streams and disposal
- 56:30Reporting progress
- 58:50Context and ConfigureAwait
related talks
55mAsync internals in .NET
59mAsynchronous Programming From The Ground Up
57mBack to Basics: Efficient Async and Await
01h 00mAvoiding common pitfalls with async/await
01h 00mCorrecting Common Async/Await Mistakes in .NET
51mAsync Internals in .NET
44mIt's All About the State, or What async/await Hides in C#?
01h 05mCorrecting Common Async/Await Mistakes in .NET 10
