Skip to main content
Source: Al0057ToAl0060ThreadingAnalyzer.cs

Description

async void methods cannot be awaited, and any exceptions they throw will crash the process. Use async Task instead.

Bad Code

public async void SendNotification()
{
    await httpClient.PostAsync("/notify", content);
}

Good Code

public async Task SendNotification()
{
    await httpClient.PostAsync("/notify", content);
}

Properties

  • Category: Threading
  • Severity: Warning
  • Enabled by default: True
  • Code fix available: False

Configuration

dotnet_diagnostic.AL0057.severity = warning