CRR0038 - The CancellationToken parameter is never used
This analyzer detects asynchronous methods that do not use the passed CancellationToken parameter.
async Task ProcessFileAsync(string path, CancellationToken cancellationToken)
{
var lines = await File.ReadAllLinesAsync(path).ConfigureAwait(false);
foreach (var line in lines)
{
//...
}
}
All asynchronous methods should accept the CancellationToken parameter and use it to cancel a task if task cancellation is requested. Refer to the Task Cancellation article for more information.
async Task ProcessFileAsync(string path, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
var lines = await File.ReadAllLinesAsync(path, cancellationToken).ConfigureAwait(false);
foreach (var line in lines)
{
cancellationToken.ThrowIfCancellationRequested();
//...
}
}