ZeroAlloc.AsyncEvents 2.0.1

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

ZeroAlloc.AsyncEvents

NuGet Build codecov License: MIT AOT GitHub Sponsors

Async events for .NET that you can actually await: a drop-in replacement for EventHandler<T> and Func<T, Task> + Task.WhenAll, with no allocations per invocation when handlers complete synchronously.

Why ZeroAlloc.AsyncEvents

  • 0 B per invocation. Raising an event whose handlers complete synchronously allocates nothing, in parallel and in sequential mode; tests assert it on net10.0 and net11.0. Naive async allocates 280 B per call.
  • More than 10× faster than Task.WhenAll fan-out, and faster than a plain synchronous multicast delegate, measured in the same run.
  • Real async semantics. Handlers return ValueTask, receive a CancellationToken, and run in parallel or in registration order. Exceptions reach the caller instead of vanishing in an async void.
  • Works under NativeAOT and trimming. No reflection; CI publishes and runs a NativeAOT sample on every build.

Install

dotnet add package ZeroAlloc.AsyncEvents

Quick start

using ZeroAlloc.AsyncEvents;

var orders = new OrderService();

orders.OrderPlaced += async (order, ct) =>
{
    await Task.Delay(10, ct);                        // e.g. send a confirmation email
    Console.WriteLine($"Emailed order {order.Id}");
};
orders.OrderPlaced += (order, ct) =>
{
    Console.WriteLine($"Audited order {order.Id}");  // completes synchronously
    return ValueTask.CompletedTask;
};

await orders.PlaceAsync(new OrderPlaced(42));

public sealed record OrderPlaced(int Id);

public partial class OrderService
{
    // The generator writes `public event AsyncEvent<OrderPlaced> OrderPlaced` for this field.
    [AsyncEvent]
    private AsyncEventHandler<OrderPlaced> _orderPlaced = new(InvokeMode.Parallel);

    public ValueTask PlaceAsync(OrderPlaced order, CancellationToken ct = default)
        => _orderPlaced.InvokeAsync(order, ct);
}

PlaceAsync returns once both handlers have finished. Subscribers use the familiar += and -=.

What you get

  • Parallel or sequential dispatch, chosen per field and overridable per call. Invoke modes
  • Cancelable events. A handler sets Cancel and the remaining handlers are skipped, for validation and veto pipelines. Cancelable events
  • Generated event accessors with [AsyncEvent] on a field or on the whole class. Mistakes are reported at compile time. Source generator, diagnostics
  • Lock-free, thread-safe subscription. Registering and unregistering never takes a lock.
  • Targets net10.0 and net11.0.
  • Async property and collection notifications, the async INotifyPropertyChanged family, come from ZeroAlloc.Notify, which builds on this package.

Performance

Ten handlers, each returning a completed task, invoked once. net10.0, BenchmarkDotNet, same run; the ratio is against a synchronous multicast delegate. Allocations are exact; speed is a same-run ratio.

Method Ratio Allocated
EventHandler<T>, sync multicast 1.00 0 B
Func<T, Task> + Task.WhenAll 11.93 280 B
ZeroAlloc.AsyncEvents, parallel 0.44 0 B
ZeroAlloc.AsyncEvents, sequential 0.61 0 B

Full results, methodology and allocation notes: docs/performance.md.

Learn more

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.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net11.0

    • No dependencies.

NuGet packages (17)

Showing the top 5 NuGet packages that depend on ZeroAlloc.AsyncEvents:

Package Downloads
AdoNet.Async.DataSet

Async DataSet and DataTable for ADO.NET (System.Data). Includes AsyncDataTable, AsyncDataSet, and AsyncDataAdapter.

AI.Sentinel

Security monitoring middleware for IChatClient — prompt injection, hallucination, and operational anomaly detection with an intervention engine.

Thalos.NET

Thalos.NET agent runtime on Microsoft Agent Framework: agent factory, tool catalog with authorization, session state machine, in-memory session store.

ZeroAlloc.EventSourcing

Source-generated event-sourced aggregates for .NET. Zero-allocation event dispatch, AOT-safe.

BlazorNative.Core

Core contracts for BlazorNative: shell bridge and interop abstractions, the INavigationManager contract, and the DI-facing primitives shared by the renderer, HTTP bridge, and component library.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.1 0 11/22/2026
2.0.0 0 11/22/2026
1.2.2 0 11/22/2026
1.2.1 5,995 11/17/2026
1.2.0 10,051 11/11/2026
1.1.12 7,870 10/30/2026
1.1.11 25,466 10/18/2026
1.1.10 3,657 10/16/2026
1.1.9 1,324 10/15/2026
1.1.8 3,154 10/11/2026
1.1.7 16,854 9/30/2026
1.1.6 3,138 9/28/2026
1.1.5 1,159 9/27/2026
1.1.4 11,266 9/20/2026
1.1.3 5,554 9/19/2026
1.1.2 19,184 5/28/2026
1.1.1 930 5/12/2026
1.1.0 810 5/1/2026
1.0.3 1,467 5/1/2026
1.0.2 1,144 4/29/2026
Loading failed