Skip to content

Latest commit

 

History

History
29 lines (21 loc) · 784 Bytes

VSTHRD100.md

File metadata and controls

29 lines (21 loc) · 784 Bytes

VSTHRD100 Avoid async void methods

Methods with async void signatures make it impossible for their caller to track the entire asynchronous operation and handle exceptions that may be thrown by that method. If the method throws an exception, it crashes the process.

Examples of patterns that are flagged by this analyzer

async void DoSomethingAsync()
{
    await SomethingElseAsync();
}

Solution

Change the method to return Task instead of void.

async Task DoSomethingAsync()
{
    await SomethingElseAsync();
}

A code fix is offered that automatically changes the return type of the method.

Refer to Async/Await - Best Practices in Asynchronous Programming for more info.