Skip to content

Repository files navigation

CronNET

CronNET is a simple C# library for running tasks based on a cron schedule.

Cron Schedules

CronNET supports most cron scheduling. See tests for supported formats.

* * * * * ┬ ┬ ┬ ┬ ┬
│ │ │ │ │
│ │ │ │ │
│ │ │ │ └───── day of week (0 - 6) (Sunday=0 )
│ │ │ └────────── month (1 - 12)
│ │ └─────────────── day of month (1 - 31)
│ └──────────────────── hour (0 - 23)
└───────────────────────── min (0 - 59)
 `* * * * *` Every minute.
`0 * * * *` Top of every hour.
`0,1,2 * * * *` Every hour at minutes 0, 1, and 2.
`*/2 * * * *` Every two minutes.
`1-55 * * * *` Every minute through the 55th minute.
`* 1,10,20 * * *` Every 1st, 10th, and 20th hours.

Console Example

usingSystem.Threading;usingCronNET;namespaceCronNETExample.Console{classProgram{privatestaticreadonlyCronDaemoncron_daemon=newCronDaemon();staticvoidMain(string[]args){cron_daemon.add_job(newCronJob("* * * * *",task));cron_daemon.start();// Wait and sleep forever. Let the cron daemon run.while(true)Thread.Sleep(6000);}staticvoidtask(){Console.WriteLine("Hello, world.")}}}

Windows Service Example

usingSystem.Threading;usingCronNET;namespaceCronNETExample.WindowsService{publicpartialclassService:ServiceBase{privatereadonlyCronDaemoncron_daemon=newCronDaemon();publicService(){InitializeComponent();}protectedoverridevoidOnStart(string[]args){cron_daemon.add_job(newCronJob("*/2 * * * *",task));cron_daemon.start();}protectedoverridevoidOnStop(){cron_daemon.stop();}privatevoidtask(){Console.WriteLine("Hello, world.")}}}

About

C# library for running cron jobs on .NET

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages