SimpleW.Service.Background 26.1.0-alpha.20260823-2061

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

SimpleW.Service.Background

website

In-process background jobs and cron scheduling for SimpleW.

Getting Started

using SimpleW;
using SimpleW.Service.Background;

var server = new SimpleWServer(System.Net.IPAddress.Any, 8080);

server.UseBackgroundModule(options => {
    options.WorkerCount = 2;
    options.JobStore = new MemoryBackgroundJobStore();
    options.DefaultJobOptions.Timeout = TimeSpan.FromMinutes(5);

    options.Schedule("cleanup", "0 2 * * *", async ctx => {
        await CleanupAsync(ctx.CancellationToken);
    });

    options.ScheduleEvery("refresh-cache", TimeSpan.FromMinutes(10), async ctx => {
        await RefreshCacheAsync(ctx.CancellationToken);
    });
});

server.MapPost("/import", (HttpSession session) => {
    string payload = session.Request.BodyString;

    BackgroundJobHandle job = session.GetBackgroundService().Enqueue("import", async ctx => {
        ctx.ReportProgress(0, "Starting import");
        await ImportAsync(payload, ctx.CancellationToken);
        ctx.ReportProgress(100, "Done");
    });

    return session.Response.Status(202).Json(new {
        accepted = true,
        jobId = job.Id
    });
});

await server.RunAsync();

Jobs are kept in memory only. They do not survive process restart.

Use ctx.ReportProgress(percent, message) from inside a job to update the latest progress exposed by GetJob(jobId).

Delayed and interval jobs

Schedule one in-process job after a delay or at a specific date:

IBackgroundService background = server.GetBackgroundService();

BackgroundJobHandle delayed = background.EnqueueAfter(
    "send-reminder",
    TimeSpan.FromMinutes(15),
    ctx => SendReminderAsync(ctx.CancellationToken)
);

BackgroundJobHandle scheduled = background.EnqueueAt(
    "close-period",
    new DateTimeOffset(2026, 12, 31, 23, 0, 0, TimeSpan.Zero),
    ctx => ClosePeriodAsync(ctx.CancellationToken)
);

ScheduleEvery uses fixed ticks and runs for the first time after one complete interval. By default, a tick is skipped while the previous occurrence is queued, running, or retrying. Set AllowConcurrentExecutions when overlapping occurrences are explicitly safe:

server.UseBackgroundModule(options => {
    options.ScheduleEvery(
        "poll-inbox",
        TimeSpan.FromSeconds(30),
        ctx => PollInboxAsync(ctx.CancellationToken),
        schedule => {
            schedule.AllowConcurrentExecutions = false;
            schedule.JobOptions.Timeout = TimeSpan.FromSeconds(20);
        }
    );
});

Retry and timeout

Defaults are copied from BackgroundOptions.DefaultJobOptions, then each job can override them:

BackgroundJobHandle import = background.Enqueue(
    "import",
    ctx => ImportAsync(ctx.CancellationToken),
    job => {
        job.Timeout = TimeSpan.FromMinutes(2);
        job.RetryCount = 3;
        job.RetryDelay = TimeSpan.FromSeconds(1);
        job.RetryBackoffFactor = 2;
        job.RetryMaxDelay = TimeSpan.FromSeconds(30);
        job.RetryOnTimeout = true;
    }
);

RetryCount is the number of additional attempts. A job keeps the same id across every attempt. Backoff delays do not occupy a worker.

Timeout and cancellation are cooperative. The module cancels ctx.CancellationToken, but it cannot forcibly stop a delegate that ignores that token. A retry never starts while the previous attempt is still executing.

Cancellation and asynchronous enqueue

Cancel delayed, queued, retrying, or running jobs by id:

bool cancellationRequested = background.Cancel(import.Id);

For backpressure, EnqueueAsync waits asynchronously until the bounded queue has capacity:

using CancellationTokenSource acceptanceTimeout = new(TimeSpan.FromSeconds(5));

BackgroundJobHandle accepted = await background.EnqueueAsync(
    "large-export",
    ctx => ExportAsync(ctx.CancellationToken),
    cancellationToken: acceptanceTimeout.Token
);

The token passed to EnqueueAsync controls only the wait for queue capacity. After acceptance, use Cancel(jobId) to cancel the job.

Telemetry is optional and follows the SimpleW telemetry switch:

server.EnableTelemetry();

server.UseBackgroundModule(options => {
    options.EnableTelemetry = true;
});

When enabled, the module emits low-cardinality counters and gauges such as simplew.background.job.enqueued.count, simplew.background.job.completed.count, simplew.background.job.retried.count, simplew.background.job.timed_out.count, simplew.background.queue.length, and simplew.background.job.running.

Metrics are tagged only with stable values like source, result, and reason. Job ids, job names, cron expressions, and progress messages are not used as metric tags.

Use options.JobStore with a custom IBackgroundJobStore to persist job snapshots in another backend. The current module still executes in-process delegates; durable replay after restart will need a future typed-job/payload model.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  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 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

  • net8.0

  • net9.0

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
26.1.0-alpha.20260823-2061 33 8/23/2026
26.1.0-alpha.20260821-2058 42 8/21/2026
26.1.0-alpha.20260813-2037 53 8/13/2026
26.0.0-alpha.20260813-2030 62 8/13/2026
26.0.0-alpha.20260428-1831 67 4/28/2026
26.0.0-alpha.20260427-1828 71 4/27/2026