Chandiman.CronScheduler 1.0.0

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

Chandiman.CronScheduler

Simple asp.net scheduler using cron syntax to schedule tasks without the need for a database.

Usage

IScheduledTask

CronScheduler only accepts 5 part and 6 part cron schedules. It works by creating a class that implements the IScheduledTask interface. IScheduledTask requires implementing the property Schedule and the method ExecuteAsync. Assign the Schedule property as your cron schedule in a string value. Example:

public class Task1 : IScheduledTask {
    public string Schedule => "* * * * *"; // Every Minute
    public ILogger<Task1> Logger { get; set; }

    public Task1(ILogger<Task1> logger)
    {
        Logger = logger;
    }

    public async Task ExecuteAsync(CancellationToken cancellationToken)
    {
        await Task.Run(() => Logger.LogInformation(DateTime.Now + " - Task1 Execute"), cancellationToken);
    }
}
Configuration

By default the scheduler only accepts 5 part crons. You can enable 6 part crons by adding the following to your appsettings.json:

"CronSchedulerOptions": {
  "IncludingSeconds": true
}

and the following your Program.cs:

.Configure<CronSchedulerOptions>(builder.Configuration.GetSection("CronSchedulerOptions"))
Add the Service and Tasks
.AddSingleton<IScheduledTask, Task1>()
.AddCronScheduler();

Notes

Currently, tasks do not have parameters and schedules are hard coded to the task. I did it this way because I wanted something simple for micro services that require running one or two tasks on a schedule. I would like to add these things, but I want to avoid adding any kind of database as that adds complexity. I might add these in the future if I can.

I made this library because I wanted a scheduler for my asp.net micro-service without having to use Quartz.net or Hangfire. If you require a more feature-full library I would suggest those two libraries.

Logs start and end times of tasks using ILogger. So if you use serilog or other loggers you will have your task logs available there if needed.

info: Chandiman.CronScheduler.SchedulerHostedService[0]
  Starting Task1
info: Task1[0]
  2025-04-05 2:50:59 AM - Task1 Execute
info: Chandiman.CronScheduler.SchedulerHostedService[0]
  Ending Task1
Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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.

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
1.0.0 245 4/3/2025