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
async
andawait
over synchronous methods and blocking calls such asWait()
andResult
. If you are creating a new project, you should build with async in mind from the start. - Unless you are using
Task.WhenAll
to wait for multiple operations simultaneously, you should directly await a...