Asynchronous Programming
async and await
async void
should only be used for event handlers otherwise you should always avoid it. Insteadasync Task
can be used which also does not require any return type.async void
is the only way to allow asynchronous event handlers to work because events do not have return types (thus cannot make use ofTask
andTask<T>
). Any other use ofasync 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.
Last updated
Was this helpful?