Soenneker.Utils.CancellationScopes 4.0.54

Prefix Reserved
dotnet add package Soenneker.Utils.CancellationScopes --version 4.0.54
                    
NuGet\Install-Package Soenneker.Utils.CancellationScopes -Version 4.0.54
                    
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="Soenneker.Utils.CancellationScopes" Version="4.0.54" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Utils.CancellationScopes" Version="4.0.54" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Utils.CancellationScopes" />
                    
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 Soenneker.Utils.CancellationScopes --version 4.0.54
                    
#r "nuget: Soenneker.Utils.CancellationScopes, 4.0.54"
                    
#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 Soenneker.Utils.CancellationScopes@4.0.54
                    
#: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=Soenneker.Utils.CancellationScopes&version=4.0.54
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Utils.CancellationScopes&version=4.0.54
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

Soenneker.Utils.CancellationScopes

A thread-safe, reusable cancellation scope for replacing a token while cancelling work associated with the previous generation.

Installation

dotnet add package Soenneker.Utils.CancellationScopes

Usage

await using var scope = new CancellationScope();

Task firstRun = RunAsync(scope.CancellationToken);

await scope.ResetCancellation(); // cancels firstRun's token and creates a fresh token

Task secondRun = RunAsync(scope.CancellationToken);

CancellationToken lazily creates the initial token source. Cancel() cancels the current token without replacing it, so later reads remain cancelled until ResetCancellation() is called.

To combine each generated token with an owning operation or application token, pass that token to the constructor:

await using var scope = new CancellationScope(applicationStopping);

Every token generation remains linked to the constructor token. Once that parent is cancelled, resetting the scope cannot produce a non-cancelled token.

Lifetime

Dispose the scope when its owner ends. Disposal cancels the current token source and releases it; subsequent token access returns CancellationToken.None, and reset becomes a no-op.

Callers that retain an older token can still observe its cancellation after a reset. Resetting does not wait for operations using that token to finish.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Soenneker.Utils.CancellationScopes:

Package Downloads
Soenneker.Blazor.Utils.ModuleImport

A Blazor utility library assisting with asynchronous module loading

Soenneker.Maui.Blazor.BrowserLogger

Adds the ability to browser console log in Blazor MAUI apps

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.54 14,311 9/4/2026
4.0.53 9,999 8/30/2026
4.0.52 269 8/30/2026
4.0.51 1,052 8/30/2026
4.0.50 2,329 8/29/2026
4.0.49 129 8/29/2026
4.0.48 36,870 7/28/2026
4.0.47 2,023 7/27/2026
4.0.46 8,840 7/21/2026
4.0.45 5,463 7/18/2026
4.0.44 5,640 7/16/2026
4.0.43 26,413 6/19/2026
4.0.42 2,919 6/18/2026
4.0.41 23,782 6/5/2026
4.0.38 33,965 4/23/2026
4.0.37 872 4/22/2026
4.0.36 35,948 3/13/2026
4.0.34 481 3/12/2026
4.0.32 374 3/12/2026
4.0.30 8,572 3/11/2026
Loading failed

Optimize allocations and hot paths