pengdows.threading 1.0.1745153040

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

pengdows.threading

A high-performance .NET 8 task coordination utility that limits concurrency, supports adaptive CPU-based scaling, and includes built-in retry logic.

Features

  • Controlled Concurrency: Queue tasks with a concurrency cap.
  • Adaptive Throttling: Automatically adjusts concurrency based on CPU usage.
  • Retry Support: Configurable retry policies with delay and attempt limits.
  • Safe Shutdown: Gracefully cancels and disposes resources.
  • Thread-Safe Events: Track queue status, failures, and concurrency shifts.

Installation

dotnet add package pengdows.threading

Note: Requires .NET 8.

Usage

var converge = new ConvergeWait(
    maxConcurrency: 8,
    adaptiveConfig: AdaptiveConfig.Default,
    cancellationToken: CancellationToken.None,
    logger: logger
);

converge.OnQueued += count => Console.WriteLine($"Queued: {count}");
converge.OnCompleted += count => Console.WriteLine($"Completed: {count}");
converge.OnError += ex => Console.WriteLine($"Error: {ex.Message}");

converge.SetRetryPolicy(RetryPolicy.Retry(3, TimeSpan.FromMilliseconds(250)));

for (int i = 0; i < 100; i++)
{
    converge.Queue(async () =>
    {
        // Your task logic here
        await Task.Delay(100);
    });
}

await converge.WaitForAllAsync();
await converge.DisposeAsync();

API Reference

ConvergeWait

  • Queue(Func<Task>): Adds a task for execution.
  • WaitForAllAsync(): Waits for all queued tasks to complete.
  • SetRetryPolicy(RetryPolicy): Sets retry logic.
  • DisposeAsync(): Cancels monitoring and releases resources.

AdaptiveConfig

Configure adaptive concurrency behavior:

new AdaptiveConfig(
    TargetCpuUsagePercent: 70f,
    MinConcurrency: 2,
    MaxConcurrency: 32,
    SamplingInterval: TimeSpan.FromSeconds(2)
);

RetryPolicy

Control retry behavior:

RetryPolicy.Retry(5, TimeSpan.FromMilliseconds(200));
RetryPolicy.None;

Events

  • OnQueued: Triggered when a task is queued.
  • OnCompleted: Triggered when a task completes successfully.
  • OnError: Triggered when a task permanently fails.
  • OnConcurrencyChanged: Triggered when adaptive concurrency adjusts.

License

MIT License

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.

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.1745153040 271 4/20/2025