Back to Devexpress

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

coderushforroslyn-401335-static-code-analysis-analyzers-library-crr0034-asynchronous-method-should-contain-async-suffix.md

latest2.2 KB
Original Source

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

  • Feb 28, 2025

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

csharp
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();
        //...
    }    
}
vb
Private Async Function ProcessFile(ByVal path As String, ByVal cancellationToken As CancellationToken) As Task
    cancellationToken.ThrowIfCancellationRequested()
    Dim lines = Await File.ReadAllLinesAsync(path, cancellationToken).ConfigureAwait(False)

    For Each line In lines
        cancellationToken.ThrowIfCancellationRequested()
    Next
       '...   
End Function

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.

csharp
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();
        //...
    }    
}
vb
Private Async Function ProcessFileAsync(ByVal path As String, ByVal cancellationToken As CancellationToken) As Task
    cancellationToken.ThrowIfCancellationRequested()
    Dim lines = Await File.ReadAllLinesAsync(path, cancellationToken).ConfigureAwait(False)

    For Each line In lines
        cancellationToken.ThrowIfCancellationRequested()
    Next
       '...   
End Function

See Also

Suppress Analyzers