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
<PackageReference Include="ZCrew.Extensions.Tasks" Version="1.0.1" />
<PackageVersion Include="ZCrew.Extensions.Tasks" Version="1.0.1" />
<PackageReference Include="ZCrew.Extensions.Tasks" />
paket add ZCrew.Extensions.Tasks --version 1.0.1
#r "nuget: ZCrew.Extensions.Tasks, 1.0.1"
#:package ZCrew.Extensions.Tasks@1.0.1
#addin nuget:?package=ZCrew.Extensions.Tasks&version=1.0.1
#tool nuget:?package=ZCrew.Extensions.Tasks&version=1.0.1
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 | Versions 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. |
-
net10.0
- Nito.AsyncEx.Coordination (>= 5.1.2)
- Nito.AsyncEx.Tasks (>= 5.1.2)
-
net8.0
- Nito.AsyncEx.Coordination (>= 5.1.2)
- Nito.AsyncEx.Tasks (>= 5.1.2)
-
net9.0
- Nito.AsyncEx.Coordination (>= 5.1.2)
- Nito.AsyncEx.Tasks (>= 5.1.2)
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 |