Asynchronous programming best practices
When working with async code, there are many best practices of which you should be aware. In this section, we will list the most important ones to remember in your day-to-day development. David Fowler, who is a veteran member of the ASP.NET team at Microsoft and a .NET expert, maintains an open source list of many other best practices. I recommend bookmarking this page for later reference while working with your own projects: https://github.com/davidfowl/AspNetCoreDiagnosticScenarios/blob/master/AsyncGuidance.md#asynchronous-programming.
These are my top recommendations (in no particular order) to follow when working with async code:
- Always prefer
awaitover synchronous methods and blocking calls such as
Result. If you are creating a new project, you should build with async in mind from the start.
- Unless you are using
Task.WhenAllto wait for multiple operations simultaneously, you should directly await a...