Soenneker.ConcurrentProcessing.Executor
3.0.2
Prefix Reserved
dotnet add package Soenneker.ConcurrentProcessing.Executor --version 3.0.2
NuGet\Install-Package Soenneker.ConcurrentProcessing.Executor -Version 3.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="Soenneker.ConcurrentProcessing.Executor" Version="3.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Soenneker.ConcurrentProcessing.Executor --version 3.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Soenneker.ConcurrentProcessing.Executor, 3.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 Soenneker.ConcurrentProcessing.Executor as a Cake Addin #addin nuget:?package=Soenneker.ConcurrentProcessing.Executor&version=3.0.2 // Install Soenneker.ConcurrentProcessing.Executor as a Cake Tool #tool nuget:?package=Soenneker.ConcurrentProcessing.Executor&version=3.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Soenneker.ConcurrentProcessing.Executor
This executor efficiently handles multiple tasks with controlled concurrency. It is ideal for managing parallel execution of tasks while ensuring that no more than a specified number of tasks run simultaneously.
Key Features
- Concurrent Execution: Limits the number of concurrent tasks to prevent overloading.
- Failure Handling with Retry Logic: Automatically retries failed tasks with exponential backoff.
- Async Semaphore: Uses a non-blocking semaphore to control concurrency and ensure thread safety.
- CancellationToken support for task cancellation.
⚠️ Note:
- This is not a background processor. It only manages concurrency for tasks that are provided during execution.
Installation
dotnet add package Soenneker.ConcurrentProcessing.Executor
Example: Executing Multiple Tasks with Concurrency Control
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Soenneker.ConcurrentProcessing.Executor;
public class Program
{
public static async Task Main(string[] args)
{
var executor = new ConcurrentProcessingExecutor(maxConcurrency: 3);
var tasks = new List<Func<CancellationToken, ValueTask>>
{
async (ct) => {
Console.WriteLine("Task 1 started");
await Task.Delay(500, ct);
Console.WriteLine("Task 1 completed");
},
async (ct) => {
Console.WriteLine("Task 2 started");
await Task.Delay(300, ct);
Console.WriteLine("Task 2 completed");
},
async (ct) => {
Console.WriteLine("Task 3 started");
await Task.Delay(700, ct);
Console.WriteLine("Task 3 completed");
},
async (ct) => {
Console.WriteLine("Task 4 started");
await Task.Delay(400, ct);
Console.WriteLine("Task 4 completed");
}
};
await executor.Execute(tasks);
}
}
Console Output
Task 1 started
Task 2 started
Task 3 started
Task 1 completed
Task 4 started
Task 2 completed
Task 3 completed
Task 4 completed
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.1)
- Nito.AsyncEx (>= 5.1.2)
- Soenneker.Extensions.Task (>= 3.0.87)
- Soenneker.Extensions.ValueTask (>= 3.0.77)
- Soenneker.Utils.Random (>= 3.0.69)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Soenneker.ConcurrentProcessing.Executor:
Package | Downloads |
---|---|
Soenneker.Cosmos.Repository
A data persistence abstraction layer for Cosmos DB |
GitHub repositories
This package is not used by any popular GitHub repositories.