The .NET Guidelines for async methods includes that such methods should have names that include an "Async" suffix.
Methods that return awaitable types such as Task
or ValueTask
should have an Async suffix.
Methods that do not return awaitable types should not use the Async suffix.
This Task
-returning method should have a name that ends with Async:
async Task DoSomething() // analyzer flags this line
{
await Task.Yield();
}
This method should not have a name that ends with Async, since it does not return an awaitable type:
bool DoSomethingElseAsync() // analyzer flags this line
{
return false;
}
Simply rename the method to end in "Async" (or remove the suffix, as appropriate):
async Task DoSomethingAsync()
{
await Task.Yield();
}
bool DoSomethingElse()
{
return false;
}
A code fix exists to automatically rename such methods.