A handful of async mistakes compile cleanly, work in a quick test, and fail later.
- async void. Nobody can await it, so callers cannot know when it has finished, and an exception inside it cannot be caught by the caller; in many apps it crashes the process. Return
Task instead. The only exception is an event handler whose signature requires void.
- Blocking with
.Result, .Wait() or .GetAwaiter().GetResult(). On a server each blocked request holds a thread; under load the thread pool runs dry. In apps with a UI thread it can deadlock. Await instead, all the way up.
- Fire and forget.
_ = SendAsync() starts work that nobody awaits: the method returns before it is done, and its exceptions vanish. Await it, or hand it to something that will.
- Two callers, two loads. Caching the result after an
await lets a second caller in before the first load finishes. Cache the Task instead, so later callers await the same load.
The compiler helps: warning CS4014 flags an async call that is not awaited, and CS1998 an async method with no await in it.
async void replaced with async Task, and a cached Task shared by every caller.