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
<PackageReference Include="Soenneker.Utils.CancellationScopes" Version="4.0.54" />
<PackageVersion Include="Soenneker.Utils.CancellationScopes" Version="4.0.54" />
<PackageReference Include="Soenneker.Utils.CancellationScopes" />
paket add Soenneker.Utils.CancellationScopes --version 4.0.54
#r "nuget: Soenneker.Utils.CancellationScopes, 4.0.54"
#:package Soenneker.Utils.CancellationScopes@4.0.54
#addin nuget:?package=Soenneker.Utils.CancellationScopes&version=4.0.54
#tool nuget:?package=Soenneker.Utils.CancellationScopes&version=4.0.54
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 | Versions 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. |
-
net10.0
- Soenneker.Extensions.Task (>= 4.0.128)
- Soenneker.Utils.AtomicResources (>= 4.0.10)
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 |
Optimize allocations and hot paths