Soenneker.Utils.BackgroundQueue
4.0.2476
Prefix Reserved
dotnet add package Soenneker.Utils.BackgroundQueue --version 4.0.2476
NuGet\Install-Package Soenneker.Utils.BackgroundQueue -Version 4.0.2476
<PackageReference Include="Soenneker.Utils.BackgroundQueue" Version="4.0.2476" />
<PackageVersion Include="Soenneker.Utils.BackgroundQueue" Version="4.0.2476" />
<PackageReference Include="Soenneker.Utils.BackgroundQueue" />
paket add Soenneker.Utils.BackgroundQueue --version 4.0.2476
#r "nuget: Soenneker.Utils.BackgroundQueue, 4.0.2476"
#:package Soenneker.Utils.BackgroundQueue@4.0.2476
#addin nuget:?package=Soenneker.Utils.BackgroundQueue&version=4.0.2476
#tool nuget:?package=Soenneker.Utils.BackgroundQueue&version=4.0.2476
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)
{
return queue.QueueValueTask(
path,
static (filePath, stoppingToken) => ImportAsync(filePath, stoppingToken),
cancellationToken);
}
}
The stateful overloads keep state separate from a static callback and avoid closure allocations. Non-stateful QueueTask() and QueueValueTask() overloads are also available.
Awaiting a queue call means the item was accepted by the bounded channel; it does not wait for that item to execute. When the channel is full, the call waits for capacity. The cancellation token passed to the queue call cancels that wait. During execution, callbacks receive the hosted service's stopping token.
Exceptions from a work item are logged and do not stop the processor. Work executes sequentially in enqueue order through the queue's single reader.
Observe completion
await queue.WaitUntilEmpty(cancellationToken);
bool busy = await queueInformation.IsProcessing(cancellationToken);
var (tasks, valueTasks) = await queueInformation.GetCountsOfProcessing(cancellationToken);
WaitUntilEmpty() includes both queued and currently executing work. Call it before host shutdown if queued work must complete: stopping the hosted service cancels the active callback and does not drain pending items.
Do not capture request-scoped services in work that may outlive the request scope. Queue stable state instead and create an appropriate service scope inside the callback when scoped dependencies are required.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.11)
- Soenneker.Atomics.ValueInts (>= 4.0.26)
- Soenneker.Extensions.Configuration (>= 4.0.871)
- Soenneker.Extensions.Double (>= 4.0.467)
- Soenneker.Extensions.MethodInfo (>= 4.0.371)
- Soenneker.Extensions.Task (>= 4.0.128)
- Soenneker.Extensions.ValueTask (>= 4.0.120)
NuGet packages (7)
Showing the top 5 NuGet packages that depend on Soenneker.Utils.BackgroundQueue:
| Package | Downloads |
|---|---|
|
Soenneker.Redis.Util
The general purpose utility library leveraging Redis for all of your caching needs |
|
|
Soenneker.Tests.FixturedUnit
A fundamental xUnit test that stores UnitFixture and provides synthetic inversion of control |
|
|
Soenneker.Cosmos.Repository
A data persistence abstraction layer for Cosmos DB |
|
|
Soenneker.ServiceBus.Transmitter
A utility library for sending Service Bus messages |
|
|
Soenneker.Tests.HostedUnit
A fundamental test that stores the TestHost and provides synthetic inversion of control |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.2476 | 0 | 8/31/2026 |
| 4.0.2475 | 0 | 8/31/2026 |
| 4.0.2474 | 81 | 8/31/2026 |
| 4.0.2473 | 40 | 8/30/2026 |
| 4.0.2472 | 51 | 8/30/2026 |
| 4.0.2471 | 45 | 8/30/2026 |
| 4.0.2470 | 34 | 8/30/2026 |
| 4.0.2469 | 297 | 8/30/2026 |
| 4.0.2468 | 36 | 8/30/2026 |
| 4.0.2467 | 400 | 8/30/2026 |
| 4.0.2465 | 182 | 8/30/2026 |
| 4.0.2464 | 33 | 8/30/2026 |
| 4.0.2462 | 150 | 8/30/2026 |
| 4.0.2459 | 321 | 8/29/2026 |
| 4.0.2458 | 42 | 8/29/2026 |
| 4.0.2456 | 42 | 8/29/2026 |
| 4.0.2455 | 40,741 | 8/26/2026 |
| 4.0.2454 | 2,232 | 8/26/2026 |
| 4.0.2452 | 1,461 | 8/25/2026 |
| 4.0.2451 | 8,645 | 8/22/2026 |
Update dependency Soenneker.Extensions.Configuration to 4.0.871 (#3231)