Soenneker.Utils.ExecutionContexts 4.0.41

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

Static helpers that run synchronous work inline on context-free threads and offload it when a SynchronizationContext is present.

Installation

dotnet add package Soenneker.Utils.ExecutionContexts

Usage

long bytes = await ExecutionContextUtil.RunInlineOrOffload(
    static path => ScanDirectory(path),
    directoryPath,
    cancellationToken);

On a UI or other thread with a non-null SynchronizationContext, the function is queued to the thread pool so the context thread is not blocked. On a normal thread-pool or console thread, it executes synchronously before the method returns.

The returned ValueTask completes with the action's result or exception. Await each returned value only once; the offloaded path is backed by IValueTaskSource rather than a reusable Task.

Cancellation

Cancellation is checked immediately and again before queued work starts. Once the delegate begins, this utility cannot cancel it because no token is passed into the delegate. Put a token in the explicit state when long-running work needs cooperative cancellation:

await ExecutionContextUtil.RunInlineOrOffload(
    static state => ProcessFiles(state.Path, state.Token),
    (Path: directoryPath, Token: cancellationToken),
    cancellationToken);

Execution-context behavior

Offloaded work uses ThreadPool.UnsafeQueueUserWorkItem, so the caller's ExecutionContext is not flowed. AsyncLocal values, impersonation state, and other execution-context data should not be assumed available inside the delegate; pass required data explicitly as state.

This utility is intended for synchronous work that may otherwise block a synchronization-context thread. It does not make synchronous I/O asynchronous, limit concurrency, or offload work when the caller has no synchronization context.

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.
  • net10.0

    • No dependencies.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Soenneker.Utils.ExecutionContexts:

Package Downloads
Soenneker.Utils.File

A utility library encapsulating asynchronous file IO operations

Soenneker.Utils.Path

Reserves unique file names and creates or generates temporary paths and directories.

Soenneker.Compression.Zip

High-performance, asynchronous ZIP compression and secure extraction for .NET

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.41 10,219 9/15/2026
4.0.40 38,680 9/12/2026
4.0.39 129,835 8/30/2026
4.0.38 18,044 8/29/2026
4.0.37 47,326 8/22/2026
4.0.36 73,601 8/8/2026
4.0.35 47,111 7/28/2026
4.0.34 118 7/28/2026
4.0.33 321 7/27/2026
4.0.32 76,188 7/16/2026
4.0.31 121 7/16/2026
4.0.30 120 7/16/2026
4.0.29 98,454 6/19/2026
4.0.28 3,511 6/19/2026
4.0.27 982 6/18/2026
4.0.26 92,807 6/6/2026
4.0.25 3,501 6/6/2026
4.0.24 6,856 6/5/2026
4.0.23 117,316 4/23/2026
4.0.22 4,253 4/22/2026
Loading failed

chore: pin workflow .NET SDK to 10.0.401