Asynchronous Programming
async and await
- async voidshould only be used for event handlers otherwise you should always avoid it. Instead- async Taskcan be used which also does not require any return type.- async voidis the only way to allow asynchronous event handlers to work because events do not have return types (thus cannot make use of- Taskand- Task<T>). Any other use of- async voiddoes not follow the TAP model and can be challenging to use, such as:- Exceptions thrown in an - async voidmethod can't be caught outside of that method.
- async voidmethods are difficult to test.
- async voidmethods can cause bad side effects if the caller isn't expecting them to be async.
 
Last updated
Was this helpful?