NetworkInspector.Jobs 0.23.0

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

NetworkInspector.Jobs

Jobs for any .NET application: asynchronous or blocking work with a state, allocation-free progress, a cooperative cancel, a bounded list of ended jobs, and a bounded stop of all jobs. The package depends only on NetworkInspector.Limits.

A job is one piece of work that runs beside the rest of the application: an import, an export, a capture. People want to see it, its progress, and its result, and to stop it. The application wants to stop all jobs at exit without hanging. This package gives both from one JobManager.

What you get

Type What it is
JobManager Starts, lists, cancels, removes, and stops jobs; raises Changed for list and lifecycle transitions
JobRequest What a job is for people and filters: name, description, kind, owner, count unit, and the instance it belongs to
JobWork, BlockingJobWork The work: asynchronous on the thread pool, or blocking on its own thread
JobContext What the work receives: id, cancellation token, progress
JobProgress, JobProgressSnapshot Status text, fraction, or count with total; written by the work, read by anyone
JobHandle, JobSnapshot The caller's view of one job: state, Read(), and Completion
JobId, JobState, JobEndReason Id from 1, states Pending → Running → Completed, Cancelled, or Failed, and why a job ended
JobFailure, JobFailureCode Why a request was refused, with one English sentence
JobsLimits The limits jobs.endedKept and jobs.stopWait

Quickstart

Prerequisites: .NET 10 or later.

dotnet add package NetworkInspector.Jobs
using NetworkInspector.Jobs;
using NetworkInspector.Limits;

TextWriter output = Console.Out;

// A manager keeps ended jobs up to jobs.endedKept; the writer owns the live value (Limit has no public constructor).
await using JobManager jobs = new(TimeProvider.System, new LimitWriter(JobsLimits.EndedKept).Limit);

// The work is not async: an async lambda without await is warning CS1998.
if (jobs.TryStart(new JobRequest("Import", "Import counters", "sample.import", "Sample Application", "rows"),
    context =>
    {
        for (long i = 0; i < 1_000_000; i++)
        {
            context.Cancellation.ThrowIfCancellationRequested();
            context.Progress.AddCount(1);
        }

        return ValueTask.CompletedTask;
    }, out JobHandle? job, out JobFailure? failure))
{
    await job.Completion;
    output.WriteLine(job.Read().State);
}
else
{
    output.WriteLine(failure.Value.Message);
}

Output:

Completed

Threads

  • Progress reports do not raise Changed or advance the list version. Read progress periodically while a job is active.
  • Start invokes lifecycle handlers inline before dispatch. Return from those handlers without waiting for the job.
  • Running jobs receive cancellation immediately. Their registrations run asynchronously. Callback errors go to HandlerFailed; its handlers must return normally.
  • Asynchronous work runs on the thread pool; after lifecycle handlers return, dispatch stays asynchronous even when the work runs long before its first await.
  • Blocking work runs on its own background thread named {Kind}-{Id}-{UiName} with the invariant culture.
  • Neither flows the starter's ExecutionContext: a job does not inherit the AsyncLocal values of the code that started it.
  • Every member of JobManager may be called from any thread. The list has no lock: it is one immutable value replaced by a compare-exchange, so readers never wait for writers.
  • The thread that changed the list raises Changed and LimitHit. Each subscriber's exception goes to HandlerFailed on that thread. Cancellation callback failures reach HandlerFailed on the thread observing their completion.

Instance

A job may belong to one instance of the application (a counter, a session): new JobRequest(…) { Instance = "counter:1" }. The library checks only the form kind:instance (a lower-case letter and up to 63 lower-case letters and digits, a colon, and 1 to 128 letters, digits, dots, dashes, or underscores) and refuses another form with JobFailureCode.InvalidRequest and a sentence that names the form; what the instance is and its name stay with the application.

Progress

JobProgress takes reports from any number of writers and serves any number of readers: a compare-exchange claims each write, so no count is lost. A report costs one uncontended compare-exchange and up to three volatile writes and allocates nothing, so a per-item loop can report every item. Read() returns a consistent snapshot (a sequence lock: it retries while a write is in progress). The fraction is count over total when the total is known, else the last SetFraction value. The rate is count per second since the start.

Limits

Key Default Range What a hit does
jobs.endedKept 1,000 1 to 1,000,000, or off The oldest ended job leaves the list; the first trim of a manager's life raises LimitHit with the hit sentence
jobs.stopWait 30 s 1 s to 1 h, or off StopAllAsync returns the jobs that did not end within the wait; the application reports them

The application offers both as settings. It passes the live Limit of jobs.endedKept to the constructor, so a change applies at the next end, and the value of jobs.stopWait to StopAllAsync (Timeout.InfiniteTimeSpan when off). The hit sentence ends with "Change the setting jobs.endedKept, or the value the application passes when it creates the job manager."

Build and test

dotnet build NetworkInspector.Jobs/NetworkInspector.Jobs.csproj -c Release
dotnet test --project NetworkInspector.Jobs.Tests/NetworkInspector.Jobs.Tests.csproj -c Release

Documentation

Architecture: Jobs

License

MIT. See the license in the repository root.

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 (2)

Showing the top 2 NuGet packages that depend on NetworkInspector.Jobs:

Package Downloads
NetworkInspector.Sessions

Session orchestration for NetworkInspector. Coordinates frame sources, protocol stack parsing, pull-based listeners, and background jobs.

NetworkInspector.BaseApp.Core

The UI-free core of a base application: identity, typed commands with one pipeline, a license gate, generic plugins, settings and profiles, messages and a log file, jobs, texts in several languages, shared UI state, and row sources for huge growing lists. It references no web or desktop framework.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.23.0 0 11/26/2026