This analyzer detects asynchronous methods that returns nothing and does not catch the inner exceptions.
async void DemoMethodAsync(CancellationToken token) {
await Task.Run(() => { DemoMethodSync(); }, token).ConfigureAwait(false);
}
Async Sub DemoMethodAsync(token As CancellationToken)
Await Task.Run(Sub() DemoMethodSync(), token).ConfigureAwait(False)
End Sub
The shown code can cause the app to crash because the exceptions thrown within a void async method cannot be caught from the outside — you should always catch them inside the method.
async void DemoMethodAsync(CancellationToken token) {
try {
await Task.Run(() => { DemoMethodSync(); }, token).ConfigureAwait(false);
} catch(Exception ex) {
Console.WriteLine(ex);
}
}
Async Sub DemoMethodAsync(token As CancellationToken)
Try
Await Task.Run(Sub() DemoMethodSync(), token).ConfigureAwait(False)
Catch ex As Exception
Console.WriteLine(ex)
End Try
End Sub
We are updating the DevExpress product documentation website and this page is part of our new experience. During this transition period, product documentation remains available in our previous format at documentation.devexpress.com. Learn More...