VOOZH about

URL: https://www.nuget.org/packages/Soenneker.Utils.BackgroundQueue/

⇱ NuGet Gallery | Soenneker.Utils.BackgroundQueue 4.0.2402




👁 Image
Soenneker.Utils.BackgroundQueue 4.0.2402

Prefix Reserved
dotnet add package Soenneker.Utils.BackgroundQueue --version 4.0.2402
 
 
NuGet\Install-Package Soenneker.Utils.BackgroundQueue -Version 4.0.2402
 
 
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="Soenneker.Utils.BackgroundQueue" Version="4.0.2402" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Utils.BackgroundQueue" Version="4.0.2402" />
 
Directory.Packages.props
<PackageReference Include="Soenneker.Utils.BackgroundQueue" />
 
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 Soenneker.Utils.BackgroundQueue --version 4.0.2402
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Soenneker.Utils.BackgroundQueue, 4.0.2402"
 
 
#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 Soenneker.Utils.BackgroundQueue@4.0.2402
 
 
#: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=Soenneker.Utils.BackgroundQueue&version=4.0.2402
 
Install as a Cake Addin
#tool nuget:?package=Soenneker.Utils.BackgroundQueue&version=4.0.2402
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

👁 alternate text is missing from this package README image
👁 alternate text is missing from this package README image
👁 alternate text is missing from this package README image
👁 alternate text is missing from this package README image

👁 alternate text is missing from this package README image
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 Task and ValueTask
  • 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 items
  • LockCounts � Enables thread-safe tracking of running work
  • Log � 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 net10.0 is compatible.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows 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 (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.2402 0 6/18/2026
4.0.2401 3,919 6/16/2026
4.0.2400 7,096 6/16/2026
4.0.2399 18,680 6/10/2026
4.0.2398 266 6/10/2026
4.0.2397 698 6/10/2026
4.0.2395 7,542 6/9/2026
4.0.2394 6,910 6/9/2026
4.0.2393 14,721 6/6/2026
4.0.2392 4,964 6/6/2026
4.0.2391 831 6/6/2026
4.0.2389 4,594 6/6/2026
4.0.2388 95 6/6/2026
4.0.2386 159 6/5/2026
4.0.2383 4,506 6/5/2026
4.0.2379 55,900 5/13/2026
4.0.2378 4,481 5/12/2026
4.0.2377 99 5/12/2026
4.0.2375 23,832 5/2/2026
4.0.2374 32,576 4/24/2026
Loading failed

Update actions/checkout action to v7 (#3036)