Appendix D. The async state machine
C# allows running code asynchronously through Tasks. Although you can create Tasks by hand, the async and await keywords make this powerful feature accessible. These keywords do a lot of heavy lifting, which can feel like magic.
The C# compiler understands how to turn code using async and await into a state machine. We’ll see how this state machine works by looking at the Common Intermediate Language (CIL; .NET’s intermediate language), generated when async is used and when it isn’t.
You can follow along with the repro steps and see how this process works if you have Visual Studio. Visual Studio comes with a tool called ildasm that we use to view the generated CIL from compiling the code. If you’re using JetBrains, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access