A method is declared async but never awaits, so it runs synchronously and pays for a state machine
What it finds
An async method without await runs to its end on the caller's thread and wraps its result in a task; the keyword adds a state machine and catches exceptions into the task without making anything asynchronous. Either an await is missing, or the method can drop async and return Task.FromResult or Task.CompletedTask. await foreach and await using count as awaits; awaits inside nested lambdas do not.
From the rule's source, async_without_await.rs.
using System.Threading.Tasks; class Loader{ async Task<int> Count()tx0 reports: Count is async but never awaits { return 3; } async Task<int> Fetch() { await Task.Yield(); return 3; } async Task Each(System.Collections.Generic.IAsyncEnumerable<int> items) { await foreach (var item in items) { } }} 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-without-await" = "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-without-await] reason="..."tx0 explain tx0/csharp:async-without-await shows the same in the terminal. Found a false positive? Report it.