> For the complete documentation index, see [llms.txt](https://dailyjournal.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dailyjournal.gitbook.io/notes/languages/c-sharp/features/asynchronous-programming.md).

# Asynchronous Programming

async and await

{% embed url="<https://learn.microsoft.com/en-us/dotnet/csharp/asynchronous-programming/>" %}

* `async void` **should only be used for event handlers otherwise you should always avoid it.** Instead [`async Task` can be used which also does not require any return type.](https://learn.microsoft.com/en-us/dotnet/csharp/asynchronous-programming/async-scenarios#:~:text=async%20void%20should%20only%20be%20used%20for%20event%20handlers.)<br>

  `async void` is the only way to allow asynchronous event handlers to work because events do not have return types (thus cannot make use of `Task` and `Task<T>`). Any other use of `async void` does not follow the TAP model and can be challenging to use, such as:

  * Exceptions thrown in an `async void` method can't be caught outside of that method.
  * `async void` methods are difficult to test.
  * `async void` methods can cause bad side effects if the caller isn't expecting them to be async.
