Ir al contenido

Async action (ARCH804)

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

Key dotnet.api.async-action · Severity warning · Category api

Actions that perform I/O such as database or network calls synchronously block threads and reduce scalability. Such actions should be async and use awaited calls.

[HttpGet("{id}")]
public IActionResult GetById(int id)
{
var user = _repository.Find(id);
return Ok(user);
}
[HttpGet("{id}")]
public async Task<IActionResult> GetById(int id, CancellationToken ct)
{
var user = await _repository.FindAsync(id, ct);
return Ok(user);
}

Make the action async Task<IActionResult> and await the async versions of the I/O calls.