TaskExecutor is a .NET library designed for efficient and controlled task execution. It supports concurrency management, task queuing, error handling, and graceful shutdown, making it ideal for applications requiring robust asynchronous task processing.
License
—
Deps
0
Install Size
—
Vulns
✓ 0
Published
May 30, 2025
$ dotnet add package task-executor
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.
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.
To use the TaskExecutor library in your project:
TaskExecutor project or include the compiled DLL in your application.TaskExecutor class and configure it as needed.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.
dotnet builddotnet run --project TaskExecutorAppThe 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();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.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.