Git Product home page Git Product logo

cronnet's Introduction

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.

How to install?

You can install this NuGet package

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.")
        }
    }
}

cronnet's People

Contributors

iminet avatar kevincolyar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cronnet's Issues

Need parameterized thread

Hello,
It works like charm. Thanks a lot.
Please can you add a parameterized thread too so that I can receive a parameter when my cron job starts.

thanks a lot.

Kind regards,
Vinay

Not allowed * 1,10,20 * * *

Hello,

I tried to schedule a task at * 1,10,20 * * * but i got bad expression error. It will be very helpful if cronNET support such kind of expression. Is there any work around for these kind of expressions?

Thank you

Doesn't work!

This doesn't work.

grafik

Can you please help me here? I just get this error:

grafik

missing license

This project looks good. Please, add a license. If you don't care, I will suggest the MIT license.

what is this mean? why you do this?

// if (DateTime.Now.Minute != _last.Minute)
// {
_last = DateTime.Now;
foreach (ICronJob job in cron_jobs)
job.execute(DateTime.Now);
// }

CronNET in Web Api

Hi,

Please, I need some guide how to implement a CronJob with async methods in WebApi, I tried put it in startup, but OWIN configure is non-async.

Thanks in advance.

Platform Not Supported Exception on Net7

I get this exception:

ortedException Thread abort is not supported on this platform.
at void System.Threading.Thread.Abort()
at void CronNET.CronJob.abort()
at void CronNET.CronDaemon.Stop()

Thread Abort is not supported in NetCore.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.