Async action (ARCH804)
هذا المحتوى غير متوفر بلغتك بعد.
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.
Incorrect
Section titled “Incorrect”[HttpGet("{id}")]public IActionResult GetById(int id){ var user = _repository.Find(id); return Ok(user);}Correct
Section titled “Correct”[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.