Ir al contenido

Unnecessary async await (ARCH108)

Esta página aún no está disponible en tu idioma.

Key dotnet.async.unnecessary-async-await · Severity info · Category async

When a method only awaits and returns a single Task, the async/await state machine adds needless overhead. Return the Task directly instead.

public async Task<Order> GetOrderAsync(int id)
{
return await _repository.FindAsync(id);
}
public Task<Order> GetOrderAsync(int id)
{
return _repository.FindAsync(id);
}

Remove async/await and return the Task directly (when there is no try/catch, using, or multiple awaits). If needed, suppress the rule per project/workspace via except/ignore.