NCrontab.Scheduler
1.0.3-pre
See the version list below for details.
dotnet add package NCrontab.Scheduler --version 1.0.3-pre
NuGet\Install-Package NCrontab.Scheduler -Version 1.0.3-pre
<PackageReference Include="NCrontab.Scheduler" Version="1.0.3-pre" />
paket add NCrontab.Scheduler --version 1.0.3-pre
#r "nuget: NCrontab.Scheduler, 1.0.3-pre"
// Install NCrontab.Scheduler as a Cake Addin #addin nuget:?package=NCrontab.Scheduler&version=1.0.3-pre&prerelease // Install NCrontab.Scheduler as a Cake Tool #tool nuget:?package=NCrontab.Scheduler&version=1.0.3-pre&prerelease
NCrontab.Scheduler
<img src="https://github.com/thomasgalliker/NCrontab.Scheduler/raw/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 | Versions 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. |
-
.NETStandard 2.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 6.0.1)
- ncrontab (>= 3.3.1)
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 | 372 | 9/20/2023 |
2.0.11-pre | 269 | 9/6/2023 |
2.0.6-pre | 201 | 8/31/2023 |
2.0.3-pre | 294 | 8/11/2023 |
2.0.0-pre | 223 | 8/10/2023 |
1.2.21-pre | 168 | 12/2/2023 |
1.2.12-pre | 217 | 7/26/2023 |
1.2.11-pre | 224 | 7/25/2023 |
1.2.10 | 27,019 | 6/20/2023 |
1.2.8-pre | 243 | 6/6/2023 |
1.2.7-pre | 241 | 5/24/2023 |
1.2.5-pre | 219 | 5/23/2023 |
1.2.3-pre | 247 | 5/19/2023 |
1.2.1-pre | 251 | 5/16/2023 |
1.1.24 | 2,242 | 4/21/2023 |
1.1.21-pre | 238 | 4/20/2023 |
1.1.17 | 14,603 | 1/31/2023 |
1.1.14-pre | 273 | 1/29/2023 |
1.1.10-pre | 286 | 1/28/2023 |
1.1.6-pre | 238 | 1/28/2023 |
1.1.4-pre | 234 | 1/27/2023 |
1.1.3-pre | 277 | 1/25/2023 |
1.0.47-pre | 245 | 1/17/2023 |
1.0.45-pre | 251 | 12/31/2022 |
1.0.44-pre | 250 | 12/27/2022 |
1.0.43 | 4,976 | 8/19/2022 |
1.0.41-pre | 323 | 7/23/2022 |
1.0.39 | 26,735 | 5/17/2022 |
1.0.37-pre | 275 | 5/17/2022 |
1.0.35 | 781 | 5/11/2022 |
1.0.34-pre | 307 | 5/6/2022 |
1.0.31-pre | 294 | 5/1/2022 |
1.0.30-pre | 285 | 5/1/2022 |
1.0.26-pre | 290 | 4/26/2022 |
1.0.25-pre | 265 | 4/26/2022 |
1.0.24 | 1,446 | 4/20/2022 |
1.0.23-pre | 279 | 4/20/2022 |
1.0.22-pre | 261 | 4/20/2022 |
1.0.21-pre | 302 | 4/20/2022 |
1.0.20 | 793 | 4/18/2022 |
1.0.17-pre | 275 | 4/18/2022 |
1.0.15-pre | 282 | 4/18/2022 |
1.0.14-pre | 309 | 4/17/2022 |
1.0.13-pre | 216 | 4/17/2022 |
1.0.12-pre | 192 | 4/17/2022 |
1.0.11-pre | 194 | 4/17/2022 |
1.0.10-pre | 197 | 4/17/2022 |
1.0.9 | 462 | 4/16/2022 |
1.0.7-pre | 189 | 4/16/2022 |
1.0.6-pre | 208 | 4/16/2022 |
1.0.5 | 457 | 4/16/2022 |
1.0.3-pre | 187 | 4/16/2022 |
1.0.2-pre | 205 | 4/16/2022 |