Skip to content

Cancellation token (ARCH101)

Key dotnet.async.cancellation-token · Severity warning · Category async

Async methods should accept a CancellationToken parameter. This allows long-running operations to be cancelled.

public async Task<Order> GetOrderAsync(int id)
{
return await _repository.FindAsync(id);
}
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.