ZCrew.Extensions.Tasks 1.0.1

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

ZCrew.Extensions.Tasks

Extensions to tasks including: unified async wrappers for delegates and async event handling.

Installation

This package is available on NuGet as ZCrew.Extensions.Tasks for these frameworks:

  • .NET 8.0
  • .NET 9.0
  • .NET 10.0
<PackageReference Include="ZCrew.Extensions.Tasks" />

Unified Async Wrappers

This library provides unified async wrappers for delegates, allowing library authors to accept both synchronous and asynchronous callbacks through a common interface.

Using an Async Wrapper

Use IAsyncAction<T> to store any of these delegate types uniformly:

using ZCrew.Extensions.Tasks;

public class NotificationService
{
    private readonly IAsyncAction<string> onNotification;

    // Accept a synchronous callback
    public NotificationService(Action<string> onNotification)
    {
        this.onNotification = onNotification.AsAsyncAction();
    }

    // Accept an async callback
    public NotificationService(Func<string, Task> onNotification)
    {
        this.onNotification = onNotification.AsAsyncAction();
    }

    // Accept an async callback with cancellation support
    public NotificationService(Func<string, CancellationToken, Task> onNotification)
    {
        this.onNotification = onNotification.AsAsyncAction();
    }

    public async Task NotifyAsync(string message, CancellationToken token = default)
    {
        await this.onNotification.InvokeAsync(message, token);
    }
}

Async Event Handlers

Traditional C# events use EventHandler which is synchronous. This library provides AsyncEventHandler for async event patterns.

Defining an Async Event

using ZCrew.Extensions.Tasks;

public class FileWatcher
{
    public event AsyncEventHandler<FileChangedEventArgs>? FileChanged;

    protected async Task OnFileChangedAsync(FileChangedEventArgs e, CancellationToken token)
    {
        await FileChanged.InvokeSequentialAsync(this, e, token);
    }
}

public class FileChangedEventArgs : EventArgs
{
    public string FilePath { get; init; } = string.Empty;
}

Subscribing to Async Events

var watcher = new FileWatcher();

watcher.FileChanged += async (sender, e, token) =>
{
    await ProcessFileAsync(e.FilePath, token);
};

Invocation Methods

// Default: handlers run one after another similar to EventHandler.Invoke
await FileChanged.InvokeAsync(this, args, token);

// Sequential: handlers run one after another
await FileChanged.InvokeSequentialAsync(this, args, token);

// Parallel: handlers run concurrently
await FileChanged.InvokeParallelAsync(this, args, token);
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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 is compatible.  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 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.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on ZCrew.Extensions.Tasks:

Package Downloads
ZCrew.StateCraft

State machine for modern .NET applications with robust safety mechanisms and fluent configuration

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 116 3/19/2026
1.0.0 109 2/22/2026
1.0.0-preview.2 453 1/24/2026