NCrontab.Scheduler 1.0.10-pre

This is a prerelease version of NCrontab.Scheduler.
There is a newer version of this package available.
See the version list below for details.
dotnet add package NCrontab.Scheduler --version 1.0.10-pre                
NuGet\Install-Package NCrontab.Scheduler -Version 1.0.10-pre                
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="NCrontab.Scheduler" Version="1.0.10-pre" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NCrontab.Scheduler --version 1.0.10-pre                
#r "nuget: NCrontab.Scheduler, 1.0.10-pre"                
#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.
// Install NCrontab.Scheduler as a Cake Addin
#addin nuget:?package=NCrontab.Scheduler&version=1.0.10-pre&prerelease

// Install NCrontab.Scheduler as a Cake Tool
#tool nuget:?package=NCrontab.Scheduler&version=1.0.10-pre&prerelease                

NCrontab.Scheduler

Version Downloads

<img src="https://raw.githubusercontent.com/thomasgalliker/NCrontab.Scheduler/develop/logo.png" width="100" height="100" alt="NCrontab.Scheduler" align="right"></img>

NCrontab.Scheduler is a simple, open source task scheduling system that can be used in any .NET application. The main component of this project is a thread-safe scheduler which facilitates very basic scheduling operations like adding, remove or changing task schedules. NCrontab.Scheduler is built on top of NCrontab.

Download and Install NCrontab.Scheduler

This library is available on NuGet: https://www.nuget.org/packages/NCrontab.Scheduler Use the following command to install NCrontab.Scheduler using NuGet package manager console:

PM> Install-Package NCrontab.Scheduler

You can use this library in any .NET Standard or .NET Core project.

API Usage

Creating a Scheduler

Scheduler implements the main scheduler operations. You can either create a new instance of Scheduler manually:

IScheduler scheduler = new Scheduler();

Alternatively, you can access the provided singleton instance Scheduler.Current or register/resolve Scheduler and IScheduler in your dependency injection framework.

serviceCollection.AddSingleton<IScheduler>(x => new Scheduler(x.GetRequiredService<ILogger<Scheduler>>()));
Add scheduled tasks

Use method AddTask with all the provided convenience overloads to add tasks to the scheduler. A task is composed of a cron pattern which specifies the recurrance interval and an action (for synchronous callbacks) or a task (for asynchronous callbacks).

Tasks can be added to the scheduler either before or after the scheduler has been started.

scheduler.AddTask(
    cronExpression: CrontabSchedule.Parse("* * * * *"), 
    action: ct => { Console.WriteLine($"{DateTime.Now:O} -> Task runs every minutes"); });

scheduler.AddTask(
    cronExpression: CrontabSchedule.Parse("*/2 * * * *"), 
    action: ct => { Console.WriteLine($"{DateTime.Now:O} -> Task runs every second minutes"); });

scheduler.AddTask(
    cronExpression: CrontabSchedule.Parse("*/3 * * * *"), 
    action: ct => { Console.WriteLine($"{DateTime.Now:O} -> Task runs every third minutes"); });
           
Starting and stopping

Use method StartAsync to start the scheduler operations. This method can be awaited which blocks all further calls until all scheduled tasks have been canceled or removed. Use Start if you prefer to start the scheduler without blocking the current execution path of your program. If the scheduler is started without having added any tasks, it just waits (and blocks) until tasks are added.

Stop attempts to cancel all scheduled tasks immediately.

Design Considerations

Scheduler algorithm

The scheduler calculates its priorities based on the given cron expression for each task. Each scheduling iteration attempts to find the task with the earliest possible execution date/time. It calculates the delay from the current date/time to selected earliest possible execution date/time. If tasks are added or removed during this wait period, the evaluation of the earliest possible execution date/time has to be repeated.

Thread-safety

All scheduler operations are kept thread-safe. Adding and removing tasks as well as starting and stopping the scheduler can be done concurrently.

Task isolation

Each task run is isolated from all other scheduled tasks. The success or failure of execution does not have any negative side effect on other scheduled tasks.

License

This project is Copyright © 2022 Thomas Galliker. Free for non-commercial use. For commercial use please contact the author.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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 NCrontab.Scheduler:

Package Downloads
NCrontab.Scheduler.AspNetCore

NCrontab.Scheduler.AspNetCore is a simple, open source task scheduling system for ASP.NET applications.

SagaFlow

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.13-pre 378 9/20/2023
2.0.11-pre 273 9/6/2023
2.0.6-pre 203 8/31/2023
2.0.3-pre 296 8/11/2023
2.0.0-pre 225 8/10/2023
1.2.21-pre 170 12/2/2023
1.2.12-pre 219 7/26/2023
1.2.11-pre 226 7/25/2023
1.2.10 27,889 6/20/2023
1.2.8-pre 245 6/6/2023
1.2.7-pre 243 5/24/2023
1.2.5-pre 221 5/23/2023
1.2.3-pre 249 5/19/2023
1.2.1-pre 253 5/16/2023
1.1.24 2,257 4/21/2023
1.1.21-pre 242 4/20/2023
1.1.17 14,680 1/31/2023
1.1.14-pre 275 1/29/2023
1.1.10-pre 288 1/28/2023
1.1.6-pre 240 1/28/2023
1.1.4-pre 236 1/27/2023
1.1.3-pre 279 1/25/2023
1.0.47-pre 247 1/17/2023
1.0.45-pre 253 12/31/2022
1.0.44-pre 252 12/27/2022
1.0.43 4,987 8/19/2022
1.0.41-pre 325 7/23/2022
1.0.39 26,778 5/17/2022
1.0.37-pre 277 5/17/2022
1.0.35 783 5/11/2022
1.0.34-pre 309 5/6/2022
1.0.31-pre 296 5/1/2022
1.0.30-pre 287 5/1/2022
1.0.26-pre 292 4/26/2022
1.0.25-pre 267 4/26/2022
1.0.24 1,461 4/20/2022
1.0.23-pre 281 4/20/2022
1.0.22-pre 263 4/20/2022
1.0.21-pre 304 4/20/2022
1.0.20 795 4/18/2022
1.0.17-pre 277 4/18/2022
1.0.15-pre 284 4/18/2022
1.0.14-pre 311 4/17/2022
1.0.13-pre 218 4/17/2022
1.0.12-pre 194 4/17/2022
1.0.11-pre 196 4/17/2022
1.0.10-pre 199 4/17/2022
1.0.9 464 4/16/2022
1.0.7-pre 191 4/16/2022
1.0.6-pre 210 4/16/2022
1.0.5 461 4/16/2022
1.0.3-pre 189 4/16/2022
1.0.2-pre 207 4/16/2022

1.0.0
- Initial release