Back to Devexpress

CRR0039 - The 'await' expression without cancellation token

coderushforroslyn-119694-static-code-analysis-analyzers-library-crr0039-the-await-expression-without-cancellation-token.md

latest1.0 KB
Original Source

CRR0039 - The 'await' expression without cancellation token

  • Feb 28, 2025

This analyzer detects asynchronous method calls without a valid CancellationToken.

csharp
await Task.Run(() => { DemoMethodSync(); }).ConfigureAwait(false);
vb
Await Task.Run(Sub() DemoMethodSync()).ConfigureAwait(False)

You should use a CancellationToken object with all asynchronous methods to be able to cancel tasks. Refer to the Task Cancellation article for more information.

csharp
await Task.Run(() => { DemoMethodSync(); }, cancellationToken).ConfigureAwait(false);
vb
Await Task.Run(Sub() DemoMethodSync(), cancellationToken).ConfigureAwait(False)

See Also

Suppress Analyzers