DeferredTaskManager 8.0.2
dotnet add package DeferredTaskManager --version 8.0.2
NuGet\Install-Package DeferredTaskManager -Version 8.0.2
<PackageReference Include="DeferredTaskManager" Version="8.0.2" />
paket add DeferredTaskManager --version 8.0.2
#r "nuget: DeferredTaskManager, 8.0.2"
// Install DeferredTaskManager as a Cake Addin #addin nuget:?package=DeferredTaskManager&version=8.0.2 // Install DeferredTaskManager as a Cake Tool #tool nuget:?package=DeferredTaskManager&version=8.0.2
Deferred Task Manager C# based on the Runners pattern
The implementation allows you to use multiple background tasks (or «runners») to process tasks from the queue. Classic runners usually do not wait, but constantly check the queue for tasks. The current implementation uses the PubSub pattern to wait for new tasks, which makes this approach more reactive but less resource-intensive.
Usage example
1️⃣ Injection of the Singleton dependency with the required data type:
services.AddSingleton<IDeferredTaskManagerService<object>, DeferredTaskManagerService<object>>();
2️⃣ Background tasks are executed in a separate thread from the background service, if desired, you can run each DeferredTaskManager in a separate thread:
internal sealed class EventManagerService : BackgroundService
{
private readonly IDeferredTaskManagerService<object> _deferredTaskManager;
public EventManagerService(IDeferredTaskManagerService<object> deferredTaskManager)
{
_deferredTaskManager = deferredTaskManager ?? throw new ArgumentNullException(nameof(deferredTaskManager));
}
protected override Task ExecuteAsync(CancellationToken cancellationToken)
{
Func<IEnumerable<object>, CancellationToken, Task> taskDelegate = (events, cancellationToken) =>
{
return Task.Delay(1000000, cancellationToken);
};
return Task.Run(() => _deferredTaskManager.StartAsync(taskDelegate, cancellationToken: cancellationToken), cancellationToken);
}
}
A delegate with your logic must be passed to the launch method. The size of the runners pool and the parameters for resending in case of errors are variable.
3️⃣ Sending data to the Deferred Task Manager for subsequent execution:
_deferredTaskManager.Add(events);
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. |
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.