Asynchronous Programming
async and await
async voidshould only be used for event handlers otherwise you should always avoid it. Insteadasync 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 ofTaskandTask<T>). Any other use ofasync 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?