A high-performance background Task/ValueTask queue
https://soenneker.com ↗// readme
Soenneker.Utils.BackgroundQueue
A bounded, single-consumer background queue for Task and ValueTask work items in hosted .NET applications.
Installation
dotnet add package Soenneker.Utils.BackgroundQueue
Registration
builder.Services.AddBackgroundQueueAsSingleton();
Registration adds the queue, its counters, and its processor as singletons, and also registers the processor as a hosted service. A normal application host starts and stops it automatically; the manual start helpers are intended for test service providers that do not run hosted services.
Optional configuration:
{
"Background": {
"QueueLength": 5000,
"LockCounts": true,
"Log": false
}
}
QueueLengthis the bounded channel capacity. Values below2use the default of5000.LockCountsenables per-kind counts returned byGetCountsOfProcessing(). Overall processing state andWaitUntilEmpty()remain available either way.Logenables per-item debug logging.
Queue work
public sealed class ImportScheduler(IBackgroundQueue queue)
{
public ValueTask QueueImport(string path, CancellationToken cancellationToken = default)…