C# library for running cron jobs on .NET
Go to file
Kevin Colyar bfe1a1f92c Merge pull request #2 from derikwhittaker/master
IoC/Mocking Support.  Added Nuget references
2013-12-14 12:20:43 -08:00
.nuget Added IoC interfaces. Nuget auto restore 2013-12-14 08:40:37 -05:00
CronNET Added IoC interfaces. Nuget auto restore 2013-12-14 08:40:37 -05:00
CronNETTests Added IoC interfaces. Nuget auto restore 2013-12-14 08:40:37 -05:00
.gitignore New gitignore. remove ignored files 2013-12-14 08:45:40 -05:00
CronNET.sln Added IoC interfaces. Nuget auto restore 2013-12-14 08:40:37 -05:00
CronNET.v12.suo New gitignore. remove ignored files 2013-12-14 08:45:40 -05:00
CronTests.nunit Merges changes from Mehdi Gholam (mgholam@hotmail.com) 2013-07-17 09:06:45 -07:00
LICENSE.md Create LICENSE.md 2013-10-17 20:27:14 -07:00
Readme.md Fixes readme formatting. 2012-01-05 09:08:31 -08:00

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

using System.Threading;
using CronNET;

namespace CronNETExample.Console
{
    class Program
    {
        private static readonly CronDaemon cron_daemon = new CronDaemon();            

        static void Main(string[] args)
        {
            cron_daemon.add_job(new CronJob("* * * * *", task));
            cron_daemon.start();

            // Wait and sleep forever. Let the cron daemon run.
            while(true) Thread.Sleep(6000);
        }

        static void task()
        {
          Console.WriteLine("Hello, world.")
        }
    }
}

Windows Service Example

using System.Threading;
using CronNET;

namespace CronNETExample.WindowsService
{
    public partial class Service : ServiceBase
    {
        private readonly CronDaemon cron_daemon = new CronDaemon();

        public Service()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            cron_daemon.add_job(new CronJob("*/2 * * * *", task));
            cron_daemon.start();
        }

        protected override void OnStop()
        {
            cron_daemon.stop();
        }

        private void task()
        {
          Console.WriteLine("Hello, world.")
        }
    }
}