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
                    
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.2476" />
                    
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.2476" />
                    
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.2476
                    
#r "nuget: Soenneker.Utils.BackgroundQueue, 4.0.2476"
                    
#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.2476
                    
#: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.2476
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Utils.BackgroundQueue&version=4.0.2476
                    
Install as a Cake Tool

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 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
  }
}
  • QueueLength is the bounded channel capacity. Values below 2 use the default of 5000.
  • LockCounts enables per-kind counts returned by GetCountsOfProcessing(). Overall processing state and WaitUntilEmpty() remain available either way.
  • Log enables 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 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. 
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.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
Loading failed

Update dependency Soenneker.Extensions.Configuration to 4.0.871 (#3231)