Understanding async machinery down to a single detail

We all use asynchronous code and we have some understanding of the machinery behind it. It’s time to see how it works and learn why it’s hard to synchronously wait for asynchronous code, how to wait for async void methods, or how to debug deadlocks. We will see the code generated by the compiler, understand synchronization contexts and integration with TPL library, reimplement part of the mechanism to fix deadlocks, or just play with internals to understand them better.

Objectives:

  • Understanding async state machine
  • Learning about synchronization contexts and how they differ between console, ASP .NET, ASP .NET Core, or desktop applications
  • Implementing custom primitives for better code control
  • Awaiting async void methods
  • Capturing all out-of-band exceptions
  • Implementing custom tasks or synchronization contexts

Requirements:

  • Windows 10 running on x86_64 architecture
  • Visual Studio 2019
  • .NET 6
  • .NET Framework 4.8
  • dnSpy
  • WinDBG + configured symbols + configured SOS for all .NET environments
  • git

Presented at