Oakrey.Async 4.0.0

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

Oakrey.Async

Oakrey.Async provides small helpers for common asynchronous workflows in .NET: async event invocation, semaphore-based locking, timeout-linked cancellation tokens, parallel task execution, and explicit context switching.

Features

  • AsyncLock wraps SemaphoreSlim acquisition in disposable and async-disposable releasers.
  • SemaphoreSlimExtensions adds Acquire and AcquireAsync helpers with idempotent release behavior.
  • Tasker runs synchronous and asynchronous action/function batches in parallel.
  • AsyncEventHandlerExtensions invokes multicast async handlers and converts synchronous handler failures into faulted tasks.
  • TimeoutCancellationTokenSource creates linked cancellation token sources with CancelAfter without leaking an internal timeout source.
  • ContextSwitchTask and ContextSwitchAwaitable support explicit thread-pool context switching for custom async workflows.

Installation

dotnet add package Oakrey.Async

Package Manager Console:

Install-Package Oakrey.Async

Examples

Use an async lock:

SemaphoreSlim semaphore = new(1, 1);

using (await AsyncLock.LockAsync(semaphore, cancellationToken))
{
    await SaveAsync(cancellationToken);
}

Use the semaphore extension:

await using (await semaphore.AcquireAsync(cancellationToken))
{
    await ProcessAsync(cancellationToken);
}

Run work in parallel:

bool allSucceeded = await Tasker.ParallelTaskerAsync(
[
    token => ValidateAsync(token),
    token => SendAsync(token)
], cancellationToken);

Invoke async event handlers:

public event AsyncEventHandler<EventArgs>? Completed;

await Completed.InvokeAsync(this, EventArgs.Empty, cancellationToken);

Create a timeout-linked token:

using CancellationTokenSource cts = TimeoutCancellationTokenSource.CreateTimeoutLinkedTokenSource(
    TimeSpan.FromSeconds(10),
    cancellationToken);

Notes

  • AsyncLock and SemaphoreSlimExtensions.Releaser release only once, even if disposed repeatedly.
  • Tasker.ParallelTasker(Func<bool>[]) returns true only when every function returns true; an empty set returns true by normal all-of semantics.
  • TimeoutCancellationTokenSource returns the linked CancellationTokenSource; dispose it when the operation is finished.

Requirements

  • .NET 11 or higher

Project Information

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net11.0

    • No dependencies.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Oakrey.Async:

Package Downloads
Oakrey.AT

Project AT is a .NET library for interacting with AT command-based devices. It provides a rich set of features for audio control, call management, SMS handling, phonebook operations, and eCall support. Designed for extensibility and ease of use, it is a tool for developers working on telecommunication and IoT applications.

Oakrey.HardwareManager.Plugin.Base

Package Description

OakreyHardwareManager.Plugin.Base

Oakrey Hardware Manager Plugin Base

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.0 62 11/13/2026
3.0.1 160 9/18/2026
3.0.0 174 7/13/2026
2.1.0 297 2/11/2026
2.0.1 169 1/6/2026
2.0.0 458 11/13/2025
1.1.1 230 9/26/2025
1.1.0 282 6/18/2025
1.0.0 421 4/16/2025