Skip to main content

CRR0034 - The asynchronous method should contain the "Async" suffix

This analyzer detects asynchronous methods without the “Async” suffix.

async Task ProcessFile(string path, CancellationToken cancellationToken)
{
    cancellationToken.ThrowIfCancellationRequested();
    var lines = await File.ReadAllLinesAsync(path, cancellationToken).ConfigureAwait(false);
    foreach (var line in lines)
    {
        cancellationToken.ThrowIfCancellationRequested();
        //...
    }    
}

Asynchronous methods should contain the “Async” suffix to differentiate synchronous and asynchronous methods. Refer to the Asynchronous programming with async and await 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();
        //...
    }    
}