DKNet

DKNet.AspCore.Tasks

A hosted startup batch for .NET developers who implement once-per-start background work.

✨ Why use it?

πŸš€ Quick Start

Use a .NET 10 console project.

dotnet new console -f net10.0 -n PackageDemo
cd PackageDemo
dotnet add package DKNet.AspCore.Tasks

Replace Program.cs with the example, then run dotnet run.

Add Microsoft.Extensions.Hosting to the console project as well (dotnet add package Microsoft.Extensions.Hosting).

using DKNet.AspCore.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddBackgroundJob<PrintTask>();
await builder.Build().RunAsync();

public sealed class PrintTask : IBackgroundTask
{
    public Task RunAsync(CancellationToken cancellationToken = default)
    {
        Console.WriteLine("Startup task ran.");
        return Task.CompletedTask;
    }
}

The host prints Startup task ran. once. Stop it with Ctrl+C; task completion does not stop the host.

πŸ—οΈ Architecture

The generic host starts BackgroundJobHost, which resolves scoped task implementations and logs failures.

One hosted service owns one async scope for all tasks. Tasks share scoped dependencies and run concurrently; this is neither a scheduler nor a readiness gate.

πŸ”„ How it works

BackgroundJobHost resolves a batch, runs tasks concurrently, catches individual exceptions and disposes the batch scope.

There is no ordering guarantee or automatic retry. The host’s stopping token reaches every task. Task completion leaves the application host running.

🧩 Features