Com.H.Threading.Scheduler.DI 11.0.1

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

Com.H.Threading.Scheduler.DI

Dependency injection extension for Com.H.Threading.Scheduler — provides IServiceCollection integration for .NET worker services hosted as Windows services, Linux daemons, or containerized microservices.

Visit the GitHub page for full documentation.

Quick start

1. Create the XML configuration

scheduler.xml

<?xml version="1.0" encoding="utf-8" ?>
<tasks_list>
  <task>
    <sys>
      <time>11:00</time>
    </sys>
    <greeting_message>Good morning! It's 11:00 AM!</greeting_message>
  </task>
</tasks_list>

2. Register the scheduler in DI

Program.cs

using Com.H.Threading.Scheduler;

var builder = Host.CreateApplicationBuilder(args);

builder.Services.AddSchedulerService(options =>
{
    options.ConfigPath = Path.Combine(AppContext.BaseDirectory, "scheduler.xml");
});

builder.Services.AddHostedService<Worker>();

var host = builder.Build();
host.Run();

3. Inject and use in a worker

Worker.cs

using Com.H.Threading.Scheduler;

public class Worker : BackgroundService
{
    private readonly ILogger<Worker> _logger;
    private readonly ISchedulerService _scheduler;

    public Worker(ILogger<Worker> logger, ISchedulerService scheduler)
    {
        _logger = logger;
        _scheduler = scheduler;
    }

    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {
        _scheduler.IsDue += async (object sender, HTaskEventArgs e, CancellationToken ct) =>
        {
            _logger.LogInformation(e["greeting_message"]);
        };
        await _scheduler.StartAsync(stoppingToken);
    }
}

Scheduling features

All scheduling features come from the base Com.H.Threading.Scheduler library (included automatically as a dependency).

Interval scheduling

Run every 3 seconds between 9:00 AM and 2:00 PM on specific days:

<sys>
  <time>09:00</time>
  <until_time>14:00</until_time>
  <interval>3000</interval>
  <dow>Monday,Thursday</dow>
</sys>

Scheduling rules

All rules compose — every condition must be true for a task to run.

Tag Description Format Example
enabled Enable or disable the task true / false true
not_before Earliest date/time to run yyyy-MM-dd HH:mm:ss 2026-06-01 08:00:00
not_after Latest date/time to run yyyy-MM-dd HH:mm:ss 2026-12-31 23:59:59
dates Specific dates (pipe-delimited) yyyy-MM-dd 2026-01-15\|\|2026-07-04
doy Days of the year Integer 1–366 1,60,120..130
eom Last day of month true / false true
bom First day of month, the same as <dom>1</dom> true / false true
dom Days of the month Integer 1–31 1,15,28..31
dow Days of the week Weekday names Monday,Friday
time Start time HH:mm 14:30
until_time End time HH:mm 23:00
interval Milliseconds between runs Positive integer 5000
ignore_log_on_restart Force re-run on restart true / false true

Before 11.0.1 bom was read but never acted on, so a task with <bom>true</bom> ran every day.

Retry on error

<sys>
  <interval>10000</interval>
  <retry_attempts_on_error>3</retry_attempts_on_error>
  <sleep_on_error>5000</sleep_on_error>
</sys>

A task that throws is tried again after a pause: sleep_on_error if set, otherwise its interval, otherwise 60 seconds (the DefaultSleepOnError option). retry_attempts_on_error limits the retries; without it there is no limit. When the retries are used up, the task waits for its next scheduled time and starts again with a full count.

Before 11.0.0 a task that threw was tried again on every tick unless both tags were set, and a task that used up its retries did not run again.

Variables

Built-in placeholders replaced at runtime:

Variable Example Result
{now{yyyy-MM-dd}} {now{yyyy-MM-dd}} 2026-04-15
{tomorrow{yyyy-MM-dd}} {tomorrow{yyyy-MM-dd}} 2026-04-16
{dir{sys}} {dir{sys}}\data C:\app\bin\data
{dir{uri}} {dir{uri}}/data file:///C:/app/bin/data

Repeat

Execute a task multiple times with different data per iteration. Supports XML (default), JSON, CSV, and pipe-separated formats:

<sys>
  <interval>60000</interval>
  <repeat content_type="json" delay_interval="500">
    [
      {"id": 1, "name": "alice"},
      {"id": 2, "name": "bob"}
    ]
  </repeat>
</sys>
<message>Processing {var{name}} (ID: {var{id}})</message>
Repeat from external source

Chain content types to fetch and parse: uri > json, uri > csv, uri > xml, etc.

<repeat content_type="uri > json" delay_interval="500">
  https://api.example.com/users
</repeat>

File URIs are also supported:

<repeat content_type="uri > csv" delay_interval="500">
  {dir{uri}}/data/users.csv
</repeat>

External settings

Fetch tag content from URLs with optional caching:

<config content_type="uri" content_cache="once_per_day">
  https://api.example.com/config
</config>

Cache options: none (default), once_per_day / daily, or milliseconds (e.g., content_cache="60000" for 60 seconds).

Dynamic scheduling with URI — skip holidays

content_type="uri" also works on scheduling rules inside <sys>. Point <enabled> at an API — if the response contains true (case-insensitive), the task runs; otherwise it's skipped:

<sys>
  <time>09:00</time>
  <dow>Monday,Tuesday,Wednesday,Thursday,Friday</dow>
  <enabled content_type="uri">https://api.example.com/is-business-day?date={now{yyyy-MM-dd}}</enabled>
</sys>

Add content_cache="once_per_day" to avoid calling the API on every tick — the result is cached until midnight:

<enabled content_type="uri" content_cache="once_per_day">https://api.example.com/is-business-day?date={now{yyyy-MM-dd}}</enabled>

Custom placeholder markers

Override the default {{ / }} markers on any tag:

<sql open-marker="[%" close-marker="%]" null-value="N/A">
  INSERT INTO users (name, email) VALUES ('[%var{name}%]', '[%var{email}%]')
</sql>

Error handling

Worker.cs

_scheduler.TaskExceptionError += async (object sender, HTaskExecutionErrorEventArgs e, CancellationToken ct) =>
{
    _logger.LogError($"Task failed: {e.Exception.Message}");
};

_scheduler.TaskLoadingError += async (object sender, HErrorEventArgs e, CancellationToken ct) =>
{
    _logger.LogError($"Config error: {e.Exception.Message}");
};

See the full documentation for more examples and details.

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.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
11.0.1 109 11/12/2026
11.0.0 142 11/11/2026
10.1.0 210 4/15/2026
10.0.0 140 4/15/2026
9.0.0.1 275 9/8/2025
9.0.0 262 12/9/2024
8.0.0.4 221 11/29/2024
8.0.0.3 226 9/24/2024
8.0.0.2 235 9/24/2024
8.0.0.1 244 9/24/2024
8.0.0 290 1/29/2024
6.0.0.2 645 9/3/2022
1.0.5 706 1/24/2022
1.0.4 593 5/8/2021
1.0.3 628 1/3/2021
1.0.2 602 1/3/2021
1.0.1 660 1/2/2021
1.0.0 649 12/17/2020

11.0.1

* Now on Com.H.Threading.Scheduler 11.0.1 or later (it was 11.0.0 or later), which fixes bom, the
 first day of the month. The tag was read and documented but never acted on, so a task with bom
 set to true ran every day. It now runs on the 1st only. If a task of yours has bom and you came
 to rely on it running daily, take the tag out.
* Nothing in this package's own code changed.

11.0.0

* New: a net11.0 build, for .NET 11. The net8.0, net9.0 and net10.0 builds stay. The major version
 is 11 because it follows the .NET generation.
* Now on Com.H.Threading.Scheduler 11.0.x, which changes what happens to a task whose handler
 throws: it is tried again after a pause instead of on every tick, and a task that used up its
 retry_attempts_on_error runs again at its next scheduled time. If you relied on a failing task
 being tried again every second, set sleep_on_error to your tick interval. The scheduler's notes
 list every change: https://www.nuget.org/packages/Com.H.Threading.Scheduler/11.0.0#releasenotes-body-tab
* Fixed: SchedulerServiceOptions.ValueProcessors had no effect. The processors are now used, and
 one with the name of a built-in processor replaces it.
* New: SchedulerServiceOptions.DefaultSleepOnError sets the pause for a failed task that has
 neither sleep_on_error nor an interval (the scheduler's default is 60 seconds).
* Dependencies: Com.H 11.0.x, and Microsoft.Extensions.DependencyInjection and
 Microsoft.Extensions.Options 10.0.11 or later (they were 8.0.0 or later).