Soenneker.Utils.BackgroundQueue
3.0.2068
Prefix Reserved
See the version list below for details.
dotnet add package Soenneker.Utils.BackgroundQueue --version 3.0.2068
NuGet\Install-Package Soenneker.Utils.BackgroundQueue -Version 3.0.2068
<PackageReference Include="Soenneker.Utils.BackgroundQueue" Version="3.0.2068" />
<PackageVersion Include="Soenneker.Utils.BackgroundQueue" Version="3.0.2068" />
<PackageReference Include="Soenneker.Utils.BackgroundQueue" />
paket add Soenneker.Utils.BackgroundQueue --version 3.0.2068
#r "nuget: Soenneker.Utils.BackgroundQueue, 3.0.2068"
#:package Soenneker.Utils.BackgroundQueue@3.0.2068
#addin nuget:?package=Soenneker.Utils.BackgroundQueue&version=3.0.2068
#tool nuget:?package=Soenneker.Utils.BackgroundQueue&version=3.0.2068
Soenneker.Utils.BackgroundQueue
A high-performance background Task/ValueTask queue
Overview
BackgroundQueue provides an efficient way to manage background task execution in .NET applications. It helps prevent application overload by processing tasks in a controlled, asynchronous manner.
Features
- Supports both
ValueTaskandTasktypes. - Configurable queue size to limit resource usage.
- Built-in tracking of running and pending tasks.
- Extension methods for easy setup and management.
- Includes a hosted service for automatic background processing.
Installation
dotnet add package Soenneker.Utils.BackgroundQueue
Register the BackgroundQueue:
void ConfigureServices(IServiceCollection services)
{
services.AddBackgroundQueueAsSingleton();
}
Starting
await serviceProvider.WarmupAndStartBackgroundQueue(cancellationToken);
For synchronous start:
serviceProvider.WarmupAndStartBackgroundQueueSync(cancellationToken);
Stopping
To stop the service:
await serviceProvider.StopBackgroundQueue(cancellationToken);
For synchronous stop:
serviceProvider.StopBackgroundQueueSync(cancellationToken);
Configuration
Configure the queue length and task tracking settings in your application:
{
"Background": {
"QueueLength": 5000,
"LockCounts": false,
"Log": false
}
}
QueueLength: Defines the maximum number of tasks in the queue.LockCounts: Enables thread-safe counting of running tasks.Log: Outputs task tracking information toILogger
Initializing the Queue
To use BackgroundQueue, you probably want to inject it via your constructor:
IBackgroundQueue _queue;
void MyClass(IBackgroundQueue queue)
{
_queue = queue;
}
Queueing Tasks
Queuing a ValueTask
Rather than wrapping the task, you can elide it directly to avoid an extra state machine:
await _queue.QueueValueTask(_ => someValueTask(), cancellationToken);
Queuing a Task
Similarly, for Task:
await _queue.QueueTask(_ => someTask(), cancellationToken);
Waiting for Queue to Empty
To ensure all queued tasks finish before proceeding:
await queue.WaitUntilEmpty(cancellationToken);
Task Tracking
The queue tracks:
- The number of active
ValueTaskandTaskinstances. - Whether any tasks are still processing.
To check if tasks are running:
bool isProcessing = await queueInformationUtil.IsProcessing(cancellationToken);
To get current task counts:
var (taskCount, valueTaskCount) = await queueInformationUtil.GetCountsOfProcessing(cancellationToken);
| 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. 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. |
-
net9.0
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.3)
- Nito.AsyncEx (>= 5.1.2)
- Soenneker.Extensions.Configuration (>= 3.0.661)
- Soenneker.Extensions.Double (>= 3.0.435)
- Soenneker.Extensions.MethodInfo (>= 3.0.339)
- Soenneker.Extensions.Task (>= 3.0.96)
- Soenneker.Extensions.ValueTask (>= 3.0.86)
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.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.2374 | 4,166 | 4/24/2026 |
| 4.0.2373 | 3,623 | 4/23/2026 |
| 4.0.2372 | 46 | 4/23/2026 |
| 4.0.2371 | 4,938 | 4/23/2026 |
| 4.0.2370 | 50 | 4/23/2026 |
| 4.0.2369 | 549 | 4/23/2026 |
| 4.0.2368 | 578 | 4/23/2026 |
| 4.0.2367 | 343 | 4/22/2026 |
| 4.0.2366 | 134 | 4/22/2026 |
| 4.0.2363 | 20,271 | 4/21/2026 |
| 4.0.2361 | 5,930 | 4/21/2026 |
| 4.0.2360 | 11,059 | 4/15/2026 |
| 4.0.2359 | 2,042 | 4/14/2026 |
| 4.0.2358 | 306 | 4/14/2026 |
| 4.0.2357 | 22,530 | 3/31/2026 |
| 4.0.2356 | 9,596 | 3/20/2026 |
| 4.0.2355 | 2,679 | 3/19/2026 |
| 4.0.2354 | 6,340 | 3/15/2026 |
| 4.0.2353 | 2,699 | 3/14/2026 |
| 3.0.2068 | 272 | 4/6/2025 |