An async method returns void, so its caller cannot await it or see its exceptions
What it finds
An exception that escapes an async void method is raised on the synchronization context and usually ends the process; the caller cannot wait for the method to finish either. async Task gives the caller both. Event handlers, which must return void, are left alone: methods with two parameters whose second is an EventArgs or named e or args, and overrides.
From the rule's source, async_void.rs.
using System;using System.Threading.Tasks; class Jobs{ public async void Start()tx0 reports: Start is async void { await Task.Delay(1); } private async void OnClick(object sender, EventArgs e) { await Task.Delay(1); } public async Task Run() => await Task.Delay(1);} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/csharp:async-void" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/csharp:async-void] reason="..."tx0 explain tx0/csharp:async-void shows the same in the terminal. Found a false positive? Report it.