DeferredTaskManager 8.0.2

dotnet add package DeferredTaskManager --version 8.0.2                
NuGet\Install-Package DeferredTaskManager -Version 8.0.2                
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="DeferredTaskManager" Version="8.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DeferredTaskManager --version 8.0.2                
#r "nuget: DeferredTaskManager, 8.0.2"                
#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.
// 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

NuGet version (DeferredTaskManager)

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