Net.Utils.TaskManager 1.0.1

dotnet add package Net.Utils.TaskManager --version 1.0.1
NuGet\Install-Package Net.Utils.TaskManager -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="Net.Utils.TaskManager" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Net.Utils.TaskManager --version 1.0.1
#r "nuget: Net.Utils.TaskManager, 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.
// Install Net.Utils.TaskManager as a Cake Addin
#addin nuget:?package=Net.Utils.TaskManager&version=1.0.1

// Install Net.Utils.TaskManager as a Cake Tool
#tool nuget:?package=Net.Utils.TaskManager&version=1.0.1

Project logo

Net.Utils.TaskManager

SonarCloud

SonarCloud CodeFactor License: MIT

C# library offering an advanced asynchronous Task Manager optimized for handling concurrent task execution with a focus on dynamic task queuing. It is specifically designed to allow runtime addition of tasks, ensuring seamless integration of newly discovered tasks into the ongoing execution process. The library demonstrates effective use of Task parallelism and continuation in .NET.

Features

  • Concurrent and asynchronous task execution.
  • Ability to add and handle tasks dynamically after the task manager has started.
  • Efficient handling of tasks with continuation support.
  • Extensible design with ITaskManager interface for customizable task addition.

Handling of Dynamic Tasks

One of the key features of Net.Utils.TaskManager is its ability to handle tasks that are added dynamically, even after the task execution has started. This is useful in scenarios where a task's execution might lead to the discovery of new tasks that need to be run in the same cycle.

Initialization

To begin using the Net.Utils.TaskManager, you must first create an instance of the TaskManager class:

var taskManager = new TaskManager();

Alternatively, if you already have a collection of tasks to execute, you can initialize the TaskManager with them:

var initialTasks = new List<Task> { /* your tasks here */ };
var taskManager = new TaskManager(initialTasks);

Methods

The TaskManager class provides the following methods:

  • AddTask(Task task) : Adds a single task to the manager.
  • AddRange(IEnumerable<Task> tasks) : Adds a collection of tasks to the manager.
  • StartAsync() : Starts executing the tasks asynchronously.
  • AwaitFinish() : Awaits the completion of all tasks.
AddTask
// Adds a new task to the manager
taskManager.AddTask(new Task(() => DoWork()));
AddRange
// Adds a range of tasks at once
taskManager.AddRange(new List<Task> { task1, task2, task3 });
StartAsync
// Starts the task manager and executes all tasks
await taskManager.StartAsync();
AwaitFinish
// Waits for all tasks to complete
await taskManager.AwaitFinish();

ITaskManager

The ITaskManager interface is designed to allow for extensibility in task management. By implementing this interface, developers can customize how tasks are added to the manager, enabling integration with different task sources or adding additional logic when tasks are registered.

public class CustomTaskManager : ITaskManager
{
    private readonly TaskManager manager;

    public CustomTaskManager(TaskManager taskManager)
    {
        manager = taskManager;
    }

    public void AddTask(Task task)
    {
        // Custom logic before adding a task
        manager.AddTask(task);
    }

    public void AddRange(IEnumerable<Task> tasks)
    {
        // Custom logic before adding a range of tasks
        manager.AddRange(tasks);
    }
}
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.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.

Version Downloads Last updated
1.0.1 305 12/5/2023
1.0.0 100 12/4/2023