Is one of your goals to improve your knowledge and skill with C#’s async features? The async Fundamentals Live Lessons I created have just been released by Pearson.
I really like the format for this lesson. I first used it at an async precompiler during CodeMash 2013. These lessons take you on a guided tour through many common mistakes developers make when using async and await in C#. In each lesson, you’ll learn ways to improve on these common mistakes.
For those developers that are new to C# async, I start by explaining the syntax and the features provided by async and await.
This character needs to learn better practices for Async programming in C#. He tries hard, but there are many subtleties to learn about async programming that he just doesn’t know. In the beginning, his async code is just a synchronous implementation with some async APIs used. He’s simply sprinkled some asynchronous APIs into fundamentally synchronous code. The result is not a good implementation:
Throughout the lessons, I’ll show you what he’s done wrong, and how to correct it. Throughout the lessons, you’ll learn what you should be doing instead of the common mistakes our little friend makes. I’ll discuss the problems associated with sync over async, async over sync. You’ll learn the dangers of async void methods. You’ll see how to properly handle and report errors in asynchronous methods. You’ll learn how to control synchronization contexts, and when you should use the default behavior, and when you should explicitly control the continuation contexts.
If some of those terms are unfamiliar, watch the live lesson. I define all of them as part of the lessons where those techniques are used.
Finally, in the last lesson, I discuss some async specific issues for unit tests. I show how to construct unit tests that control the order of task completion, and whether any task completes successfully or with errors.
In the end, you’ll have some squeaky clean async code:
I hope you check it out. It will help you learn more about async programming. I hope the lighthearted look at common mistakes provides a good way to learn and understand the subtle issues associated with async programming.
I think the language teams have created a great set of features for async programming. These techniques will help you use them wisely.
Special thanks to John Lucas for the artwork and the design of the code smell pig.
All of these projects are Open Source (using the Creative Commons license for content, and the MIT license for code). If you would like to contribute, visit our GitHub Repository. Or, if you have questions, comments, or ideas for improvement, please create an issue for us.