Soenneker.Utils.BackgroundQueue
4.0.2294
Prefix Reserved
dotnet add package Soenneker.Utils.BackgroundQueue --version 4.0.2294
NuGet\Install-Package Soenneker.Utils.BackgroundQueue -Version 4.0.2294
<PackageReference Include="Soenneker.Utils.BackgroundQueue" Version="4.0.2294" />
<PackageVersion Include="Soenneker.Utils.BackgroundQueue" Version="4.0.2294" />
<PackageReference Include="Soenneker.Utils.BackgroundQueue" />
paket add Soenneker.Utils.BackgroundQueue --version 4.0.2294
#r "nuget: Soenneker.Utils.BackgroundQueue, 4.0.2294"
#:package Soenneker.Utils.BackgroundQueue@4.0.2294
#addin nuget:?package=Soenneker.Utils.BackgroundQueue&version=4.0.2294
#tool nuget:?package=Soenneker.Utils.BackgroundQueue&version=4.0.2294
Soenneker.Utils.BackgroundQueue
A high-performance background Task / ValueTask queue
Overview
BackgroundQueue provides a fast, controlled way to execute background work in .NET applications.
It prevents overload by queueing and processing work asynchronously with configurable limits and built-in tracking.
Features
- Supports both
TaskandValueTask - Configurable queue size
- Tracks running and pending work
- Simple DI registration
- Hosted service for automatic background processing
Installation
dotnet add package Soenneker.Utils.BackgroundQueue
Register the queue:
void ConfigureServices(IServiceCollection services)
{
services.AddBackgroundQueueAsSingleton();
}
Starting & Stopping
Start
await serviceProvider.WarmupAndStartBackgroundQueue(cancellationToken);
Synchronous start:
serviceProvider.WarmupAndStartBackgroundQueueSync(cancellationToken);
Stop
await serviceProvider.StopBackgroundQueue(cancellationToken);
Synchronous stop:
serviceProvider.StopBackgroundQueueSync(cancellationToken);
Configuration
{
"Background": {
"QueueLength": 5000,
"LockCounts": false,
"Log": false
}
}
QueueLength– Maximum number of queued itemsLockCounts– Enables thread-safe tracking of running workLog– Enables debug logging
Using the Queue
Inject IBackgroundQueue:
IBackgroundQueue _queue;
void MyClass(IBackgroundQueue queue)
{
_queue = queue;
}
Queueing a ValueTask
await _queue.QueueValueTask(_ => someValueTask(), cancellationToken);
Queueing a Task
await _queue.QueueTask(_ => someTask(), cancellationToken);
⚠️ Performance Tip: Prefer Stateful Queueing
Avoid capturing variables in lambdas when queueing work. Captured lambdas allocate and can impact performance under load.
❌ Avoid (captures state)
await _queue.QueueTask(ct => DoWorkAsync(id, ct));
If id is a local variable, this creates a closure.
✅ Recommended: Pass State Explicitly
Use the stateful overloads with static lambdas.
ValueTask
await _queue.QueueValueTask(
myService,
static (svc, ct) => svc.ProcessAsync(ct),
ct);
Task
await _queue.QueueTask(
(logger, id),
static (s, ct) => s.logger.RunAsync(s.id, ct),
ct);
Why this is better:
- No closure allocations
- Lower GC pressure
- Best performance for high-throughput queues
The non-stateful overloads remain available for convenience, but stateful queueing is recommended for hot paths.
Waiting for the Queue to Empty
await queue.WaitUntilEmpty(cancellationToken);
Task Tracking
Check if work is still processing:
bool isProcessing = await queueInformationUtil.IsProcessing(cancellationToken);
Get current counts:
var (taskCount, valueTaskCount) =
await queueInformationUtil.GetCountsOfProcessing(cancellationToken);
| 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.3)
- Soenneker.Asyncs.Locks (>= 4.0.23)
- Soenneker.Extensions.Configuration (>= 4.0.782)
- Soenneker.Extensions.Double (>= 4.0.450)
- Soenneker.Extensions.MethodInfo (>= 4.0.354)
- Soenneker.Extensions.ValueTask (>= 4.0.105)
- Soenneker.Utils.Delay (>= 4.0.51)
NuGet packages (6)
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.Integration
An abstract xUnit test class for end-to-end integration (involving WebApplicationFactory) tests |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.2294 | 1,470 | 3/5/2026 |
| 4.0.2293 | 4,354 | 3/5/2026 |
| 4.0.2292 | 72 | 3/5/2026 |
| 4.0.2291 | 64 | 3/4/2026 |
| 4.0.2290 | 340 | 3/4/2026 |
| 4.0.2289 | 31 | 3/4/2026 |
| 4.0.2288 | 34 | 3/4/2026 |
| 4.0.2287 | 6,524 | 3/4/2026 |
| 4.0.2286 | 34 | 3/4/2026 |
| 4.0.2285 | 37 | 3/4/2026 |
| 4.0.2284 | 30 | 3/4/2026 |
| 4.0.2283 | 8,365 | 3/3/2026 |
| 4.0.2282 | 9,149 | 2/28/2026 |
| 4.0.2281 | 3,137 | 2/28/2026 |
| 4.0.2280 | 4,861 | 2/27/2026 |
| 4.0.2279 | 2,236 | 2/27/2026 |
| 4.0.2278 | 6,366 | 2/26/2026 |
| 4.0.2277 | 9,945 | 2/22/2026 |
| 4.0.2276 | 5,115 | 2/21/2026 |
| 4.0.2275 | 8,969 | 2/12/2026 |