Skip to main content

CRR0033 - The void async method should be in a try/catch block

This analyzer detects asynchronous methods that return nothing and do not catch the inner exceptions.

async void DemoMethodAsync(CancellationToken token) {
    await Task.Run(() => { DemoMethodSync(); }, token).ConfigureAwait(false);
}

The code above can cause the application to crash because the exceptions that are thrown inside an asynchronous void method cannot be caught from the outside. You should catch the exceptions inside the method.

async void DemoMethodAsync(CancellationToken token) {
    try {
        await Task.Run(() => { DemoMethodSync(); }, token).ConfigureAwait(false);
    } catch(Exception ex) {
        Console.WriteLine(ex);
    }
}