Cancellation token (ARCH101)
Esta página aún no está disponible en tu idioma.
Key dotnet.async.cancellation-token · Severity warning · Category async
Async methods should accept a CancellationToken parameter. This allows long-running operations to be cancelled.
Incorrect
Section titled “Incorrect”public async Task<Order> GetOrderAsync(int id){ return await _repository.FindAsync(id);}Correct
Section titled “Correct”public async Task<Order> GetOrderAsync(int id, CancellationToken cancellationToken){ return await _repository.FindAsync(id, cancellationToken);}Add a CancellationToken parameter and pass it through to downstream async calls. If needed, suppress the rule per project/workspace via except/ignore.