Async Task Closures
10/26/2025
In .NET async methods get compiled to an async state machine. When awaiting a method call returning a Task the state of the current method is captured by a compiler generated value type, that also implements IAsyncStateMachine.
In this blog post I use .NET 9 to explore some internals of this behavior.
Capturing Structs
I have recently encountered one such async method in production code. The method received a few input parameters, created a struct instance populating its properties with the input parameters. Then serialized the struct instance to string and sent an HTTP POST request using HttpClient while awaiting the result.