AsyncEventBus 1.0.6

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

Installation

Use provided nuget package or download the source.

NuGet

About

This library contains two EventBus implementations: AsyncEventBus, which is thread-safe and designed for asynchronous and multi-threaded operations; and SyncEventBus, which is thread-safe and synchronous. The core concept is subscribing to any event represented by a class/struct with optional input parameters and a constructor to initialize them (recommended). When an event is published, its subscribed handlers receive an instance of the class (i.e., the event) with the necessary parameters.

Features<br/> ✅ Asynchronous<br/> ✅ Multi-threading<br/> ✅ Thread-safe<br/> ✅ Retry policy<br/> ✅ Execution reporting<br/> ✅ Configurable

Using

Event

An event is a class/struct that inherits from IEvent. You can define parameters for the handler within the class (properties are recommended), as well as a constructor to initialize them.

public class TestEvent : IEvent
{
    public int Value { get; init; }
    
    public TestEvent(int value)
    {
        Value = value;
    }
}

Init and Dispose

AsyncEventBus _asyncEventBus = EventBusFactory.CreateAsync();
SyncEventBus _syncEventBus = EventBusFactory.CreateSync();
// Do Something
_asyncEventBus.DisposeAsync();
_syncEventBus.Dispose();
  • Init: via factory.
  • Dispose: EventBus has a built-in Dispose method that fully cleans up the EventBus instance. Calling any EventBus method after disposal will throw an ObjectDisposedException. For AsyncEventBus, the Dispose method is asynchronous: DisposeAsync.

Subscribe

There’s no need to declare events explicitly in the EventBus; an event is automatically added to the bus on the first Subscribe call for that event. Subscription is done by specifying the event type and a handler whose parameter is the event class/struct. You can also use the subscribeOnce: bool parameter. After the first publication of the event, all its subscribers with subscribeOnce = true will be unsubscribed automatically.

private async Task Handler(TestEvent @event)
{
    var value = @event.Value;
}
_eventBus.Subscribe<TestEvent>(Handler);
// OR
_eventBus.Subscribe<TestEvent>(Handler, true);

Unsubscribe

Unsubscription is done via the return value of the Subscribe method: IDisposable. Its Dispose method unsubscribes the handler from the event.

IDisposable token = _eventBus.Subscribe<TestEvent>(Handler);
token.Dispose();

Publish

For AsyncEventBus, use PublishAsync, which sends the event invocation to a Channel queue. For SyncEventBus, call Publish, which immediately starts invoking all handlers.

await asyncEventBus.PublishAsync(new TestEvent(10));
syncEventBus.Publish(new TestEvent(10));

Clear

The bus provides two cleanup methods (apart from full cleanup via Dispose): Clear and ClearAll.

  • Clear: removes a specific event and all its handlers.
  • ClearAll: clears all events and all handlers.
_eventBus.Clear<TestEvent>();  
_eventBus.ClearAll();

Config

You can specify custom parameters for certain EventBus settings.

Parameter Description Type Defaults AsyncBus SyncBus
ShutdownTimeout Time to wait for handlers to complete when shutting down the EventBus TimeSpan 5 seconds ✅ ❌
MaxRetryCount Number of retry attempts when a handler fails. Value 0 means no retries. Delay between retries in seconds: $$2^i$$, where i is the attempt number starting from 0 int 2 ✅ ❌
EnableReporting Enable/disable execution reporting (more details below) bool true ✅ ✅
MaxReportHistory Maximum number of stored reports int 5 ✅ ✅

More About Reports

EventBus provides the GetEventReport method, which returns the latest report for a given event type (if specified) or all reports. Return type is EventPublishReport.

Properties of EventPublishReport:

  • EventType: Type – the event type
  • HandlersCount: int – number of subscribed handlers
  • ErrorHandlers: int – number of handlers that threw an error during execution
  • Exceptions: List<Exception> – thrown exceptions
var config = AsyncEventBusConfig.Default with
{
    ShutdownTimeout = TimeSpan.FromSeconds(30),
    MaxRetryCount = 3,
    EnableReporting = true
};
var eventBus = EventBusFactory.CreateAsync(config);

Sync vs Async: When to Use Which

SyncEventBus:

  • Event processing is fast and synchronous
  • Guarantees handler invocation order
  • Guarantees handler completion order
  • ⚠️ Subsequent code runs only after ALL handlers finish

AsyncEventBus:

  • High performance and non-blocking processing
  • Events are processed in the background
  • Guarantees handler invocation order
  • Handlers run concurrently, the fastest finishes first
  • ⚠️ Does NOT guarantee handler completion order
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.6 137 7/19/2026
1.0.5 142 2/4/2026
1.0.4 127 2/4/2026
1.0.3 134 2/4/2026
1.0.2 133 2/4/2026
1.0.1 130 2/4/2026
1.0.0 145 2/4/2026