Practice mode C#

Why should async void methods generally be avoided except for event handlers?

Correct answer B. Callers cannot await them or catch their exceptions

Explanation

An async void method returns nothing that callers can await, so they cannot know when it finishes, and exceptions it throws are raised directly on the synchronisation context, often crashing the application. Returning Task lets callers await completion and observe failures. async void exists mainly because event handlers must return void.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.