TastenTiger.Analyzers.Async.EnforceCancellationToken 1.0.1

Requires NuGet 2.12 or higher.

dotnet add package TastenTiger.Analyzers.Async.EnforceCancellationToken --version 1.0.1
                    
NuGet\Install-Package TastenTiger.Analyzers.Async.EnforceCancellationToken -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TastenTiger.Analyzers.Async.EnforceCancellationToken" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TastenTiger.Analyzers.Async.EnforceCancellationToken" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="TastenTiger.Analyzers.Async.EnforceCancellationToken" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TastenTiger.Analyzers.Async.EnforceCancellationToken --version 1.0.1
                    
#r "nuget: TastenTiger.Analyzers.Async.EnforceCancellationToken, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TastenTiger.Analyzers.Async.EnforceCancellationToken@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TastenTiger.Analyzers.Async.EnforceCancellationToken&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=TastenTiger.Analyzers.Async.EnforceCancellationToken&version=1.0.1
                    
Install as a Cake Tool

TastenTiger.Analyzers.Async.EnforceCancellationToken

A Roslyn analyzer that ensures asynchronous methods, those returning Task or ValueTask, include a CancellationToken as their final parameter.

Get it on Codeberg

Why enforce CancellationToken usage?

Asynchronous operations often involve I/O, long-running work, or external dependencies. When a caller no longer needs the result, continuing the operation wastes CPU time, memory, and other server resources.

Most asynchronous .NET Methods already include a CancellationToken as their last parameter. This analyzer enforces this best practice via compilation warning.

Requiring a CancellationToken:

  • Allows callers to cancel work early
  • Reduces an unnecessary load on your system
  • Encourages predictable async APIs
  • Enforces best practices

What this analyzer does

  • Produces the TA0001 compilation warning for methods that
    • use the async keyword
    • return a Task
    • return a ValueTask
  • Provides a bulk quick fix to automatically add System.Threading.CancellationToken cancellationToken = default parameter to the end of the parameter list

Examples

public async Task DoWorkAsync() // <-- violating TA0001 
{
}

public async Task DoWorkAsync(CancellationToken cancellationToken = default) // <-- complying TA0001
{
}

For more examples see TastenTiger.Analyzers.Async.EnforceCancellationToken.Sample.Examples.cs

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 0 2/10/2026
1.0.0 0 2/10/2026