Pocok.BackgroundWork 0.2.0-alpha.7

Prefix Reserved
This is a prerelease version of Pocok.BackgroundWork.
dotnet add package Pocok.BackgroundWork --version 0.2.0-alpha.7
                    
NuGet\Install-Package Pocok.BackgroundWork -Version 0.2.0-alpha.7
                    
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="Pocok.BackgroundWork" Version="0.2.0-alpha.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Pocok.BackgroundWork" Version="0.2.0-alpha.7" />
                    
Directory.Packages.props
<PackageReference Include="Pocok.BackgroundWork" />
                    
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 Pocok.BackgroundWork --version 0.2.0-alpha.7
                    
#r "nuget: Pocok.BackgroundWork, 0.2.0-alpha.7"
                    
#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 Pocok.BackgroundWork@0.2.0-alpha.7
                    
#: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=Pocok.BackgroundWork&version=0.2.0-alpha.7&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Pocok.BackgroundWork&version=0.2.0-alpha.7&prerelease
                    
Install as a Cake Tool

Pocok.BackgroundWork

Compatibility tier: experimental alpha. This package is packable and tested but is not release-eligible until its Windows and Ubuntu acceptance gate passes.

Pocok.BackgroundWork provides small lifecycle primitives for event-driven .NET services:

  • guarded observation of intentionally non-awaited Task and Task<T> instances;
  • coalescing bursts into one active execution and at most one pending rerun;
  • quiet-period debounce without overlapping operations;
  • awaited, non-overlapping repeated work.

It is not a retry library, durable scheduler, distributed queue, cron implementation, or hosted-service framework. Polly may be used inside an operation when resilience policies are required.

Guarded task observation

A source task may be detached from the caller only when a general fault handler is supplied. Filtered handlers run in registration order before the fallback. The returned TaskObservation keeps the outcome observable during tests and controlled shutdown.

TaskObservation observation = ReadDeviceAsync(cancellationToken).Observe(
    onFault: exception => LogFailure(exception),
    configure: options => options
        .OnSuccess(() => RecordSuccess())
        .OnCanceled(exception => RecordCancellation(exception))
        .OnFault<TimeoutException>(exception => RecordTimeout(exception)));

TaskObservationResult result = await observation.Completion;

Completion never faults. Source faults and cancellations are exposed through SourceException. Predicate and callback failures, including observation-token cancellation, are exposed through ObserverException.

The observation token controls callback dispatch and callback waiting. It cannot cancel a source task that was not created with that token.

Coalescing

Use CoalescingTaskRunner when many triggers should produce one current operation and at most one later rerun.

await using var refresh = new CoalescingTaskRunner(
    ReloadAsync,
    new CoalescingTaskRunnerOptions
    {
        MinimumInterval = TimeSpan.FromMilliseconds(250)
    });

await refresh.RequestAsync(cancellationToken);

All requests in one drain cycle share its completion task. Caller cancellation cancels only that caller's wait. StopAsync cancels shared work and permanently closes the runner.

Debounce

Use DebouncedTaskRunner when an operation should begin only after incoming events remain quiet.

await using var reload = new DebouncedTaskRunner(
    ReloadAsync,
    new DebouncedTaskRunnerOptions
    {
        QuietPeriod = TimeSpan.FromMilliseconds(250)
    });

_ = reload.RequestAsync().Observe(ReportReloadFailure);

Requests received while the operation is running schedule one later execution. The quiet period is measured from the latest request, so the rerun starts immediately when that period has already elapsed by the time the current operation completes.

Repetition

TaskRepeater.RepeatAsync returns the complete repeat lifecycle and never overlaps iterations. The interval is measured from one operation completion to the next operation start.

await TaskRepeater.RepeatAsync(
    PollAsync,
    new TaskRepeaterOptions
    {
        Interval = TimeSpan.FromSeconds(5),
        MaximumIterations = 10
    },
    cancellationToken);

All timing primitives accept TimeProvider, allowing deterministic tests without wall-clock sleeps.

Failure policy

Coalescing, debounce, and repetition stop on the first failure by default. BackgroundWorkFailurePolicy.Continue requires an explicit OnFailure callback. If that callback fails, the operation and callback failures are combined in an AggregateException and execution stops.

All runners are safe for concurrent requests. Operations are awaited and never overlap. Dispose runners asynchronously to cancel pending work and release lifecycle resources.

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.
  • net10.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Pocok.BackgroundWork:

Package Downloads
Pocok.Localization

Deterministic string-localizer composition with external JSON and RESX resource loading.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.0-alpha.7 70 7/20/2026