task-executor 2.0.4

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

TaskExecutor

NuGet Version NuGet Downloads

TaskExecutor is a .NET 8.0 library that provides a concurrency-controlled task execution framework. It allows you to enqueue tasks and execute them with a specified level of concurrency.

This library implements the Active Object design pattern, which decouples method execution from method invocation to enhance concurrency and simplify synchronized access to shared resources.

Features

  • Limited Concurrent Tasks: Restrict the number of tasks running simultaneously.
  • Automatic Task Execution: Automatically start a new task as soon as one completes.
  • Concurrency Control: Dynamically adjust the number of concurrent tasks.
  • Task Queue: Enqueue tasks with unique IDs and execute them asynchronously.
  • Error Handling: Capture and handle task-specific errors via an event.
  • Graceful Shutdown: Stop the executor and wait for running tasks to complete.

Getting Started

Prerequisites

  • .NET 8.0 SDK

Installation via NuGet

You can install the TaskExecutor library via NuGet Package Manager: dotnet add package task-executor Or add the following to your .csproj file: <PackageReference Include="task-executor" Version="*" /> Replace * with the desired version.

Using the Library

To use the TaskExecutor library in your project:

  1. Add a reference to the TaskExecutor project or include the compiled DLL in your application.
  2. Create an instance of the TaskExecutor class and configure it as needed.

Example Test Application

A test application is included in the repository to demonstrate how to use the TaskExecutor library. The test application is located in the TaskExecutorApp project.

Running the Test Application
  1. Open a terminal in the project directory.
  2. Build the solution: dotnet build
  3. Run the test application: dotnet run --project TaskExecutorApp
Example Code

The Program.cs file in the TaskExecutorApp project demonstrates how to use the TaskExecutor library:

var cts = new CancellationTokenSource();
using var executor = new TaskExecutor.TaskExecutor(3, cts.Token);

executor.OnTaskError += (id, ex) => Console.WriteLine($"Task {id} error: {ex.Message}");

for (int i = 0; i < 20; i++)
{
    int id = i;
    executor.EnqueueTask(id, async () =>
    {
        Console.WriteLine($"Task {id} started");
        await Task.Delay(Random.Shared.Next(2000, 5000));
        Console.WriteLine($"Task {id} finished");
    });
}

await Task.Delay(1000);

while (executor.HasRunningTasks)
{
    await Task.Delay(1000);
}
await executor.StopAsync();

Project Structure

  • TaskExecutor/: Contains the TaskExecutor library source code.
    • TaskExecutor.cs: Core implementation of the TaskExecutor class.
    • TaskForExecute.cs: Represents a task with an ID and a function to execute.
  • TaskExecutorApp/: Test application demonstrating the usage of the TaskExecutor library.
    • Program.cs: Example usage of the TaskExecutor.
  • TaskExecutor.sln: Solution file for building the library and test application.

License

MIT License

Copyright (c) 2025 Serhiy Krasovskyy xhunter74@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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 was computed.  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 was computed.  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.
  • 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.

Version Downloads Last Updated
2.0.4 121 5/30/2025
2.0.3 126 5/30/2025
2.0.2 153 5/29/2025
2.0.1 145 4/29/2025
2.0.0 155 4/28/2025
1.0.0 140 4/28/2025

2025-05-30 Have been Set initial value for Queue Polling Delay Milliseconds to avoid incorrect queue looping
2025-05-30 Added queue polling delay constructor parameter and QueuePollingDelayMilliseconds property
2025-05-29 Refactored code. Improved stability.
2025-04-29 Added .ConfigureAwait(false) to all asynchronous calls in TaskExecutor to improve performance and avoid deadlocks.
2025-04-27 Initial version