Mapping CancellationToken in controller's actions
Author: juchomCreated Sep 29, 2021Updated Sep 30, 2021
We often see code like that
public async Task<IActionResult> Get()
{
await Task.Delay(1000);
return View();
}Is it a good practice to add the CancellationToken parameter to actions when it goes async and pass this parameter to async methods ?
public async Task<IActionResult> Get(int id, CancellationToken cancellationToken)
{
await Task.Delay(1000, cancellationToken);
return View();
}Source: davidfowl/AspNetCoreDiagnosticScenarios