# Asynchronous Programming

{% 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)<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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dailyjournal.gitbook.io/notes/languages/c-sharp/features/asynchronous-programming.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
