Correcting Common Async/Await Mistakes in .NET 9
summary
Shows that the C# compiler turns async methods into state machine structs (about +80 bytes in release) and always wraps MoveNext in a try/catch that can hide exceptions if a Task is not awaited. Demonstrates fixes in a .NET MAUI Hacker News app using sharplab.io, replacing async void with a NuGet safe fire and forget pattern, using Task.WhenEach (new in .NET 9) and IAsyncEnumerable to stream results, ConfigureAwait(false)/ConfigureAwaitOptions, ValueTask and WaitAsync to improve latency, correctness and exception visibility.
AI-written summary · about
chapters (10)
- 0:00Introduction and resources
- 1:03Async/await under the hood
- 3:25Compiler-generated state machines
- 10:16The danger of unawaited tasks
- 12:54Review of async fundamentals
- 14:15Fixing common mistakes
- 21:06Handling fire-and-forget tasks
- 23:04Best practices for async methods
- 34:07Advanced performance optimizations
- 45:33Summary and Q&A
related talks
01h 00mCorrecting Common Async/Await Mistakes in .NET
01h 05mCorrecting Common Async/Await Mistakes in .NET 10
56mCorrecting Common Async/Await Mistakes in .NET 8
01h 00mCorrecting Common Async/Await Mistakes in .NET 8
49mCorrecting Common Mistakes in Asynchronous .NET Code
01h 15mBest Practices for Using async and await
01h 00mAvoiding common pitfalls with async/await
55mAsync internals in .NET
