NCron is a .Net scheduling framework, it is a .Net version of Cron
- the time based job scheduler found on unix like operating systems or Cron4j
- scheduling library for Java. Ncron is light weight and easy to use, with little
learning curve. It comes with some cool advantages, being that you can use it in
C#, Vb.net or any other .Net programming language. It takes your mind off the details
of scheduling and you can focus on how to implement the business logic of your application
or the job to be scheduled. Details such as threading and timers have been taken
You can point your browser to
the ncron library. You need to add reference to the Ncron library in your project
so as to be able to access the classes and functionalities of the Ncron scheduling
Scheduling a Job
When creating a job to be scheduled using NCron, the job is wrapped up in a class
which must extend the class NCron.CronJob
and override a void method
public class MyJob : NCron.CronJob
public override void Execute()
The job to be scheduled will be placed in the Execute method. The next thing to
do is to give NCron control over the job execution, by calling the static method
at the entry point of your application, for example this
can be put in the Main method. You should have a static setup method, which
I called JobSetup method that will be passed into the Bootstrap.Init() method.
public class Program
private static void Main(string args)
private static void JobSetup(SchedulingService schedulingService)
schedulingService.At("* * * * *").Run()<MyJob>;
The line of code inside the JobSetup method is to specify how the Job is going to
be run, and the parameter in the schedulingService.At() method is known as crontab
expression which I will discuss shortly. The SchedulingService class has a number
of methods of interest.
service.Daily().Run<MyJob>(); //runs the scheduled job once
service.Hourly().Run<MyJob>(); //runs the scheduled job once
service.Weekly().Run<MyJob>(); //runs the scheduled job once
A crontab expression is a string comprising of 5 characters, which are seperated
by space. This crontab expression when parsed produces occurrences of time based
on a given schedule expressed in the crontab format. NCron parses crontab expression
through the use of NCrontab
(Crontab for .Net) an open source library
for parsing crontab expressions.
A regular crontab expression is of the form
* * * * *
where the first * is for minute which can be from 0-59.
The second * is for hour which can also be from 0-23.
The third * is for day of the month from 1-31.
The fourth * is for month from 1-12.
The last * is for day of week from 0-6 where 0 represents Sunday.
The asterisk or wildcard character if left in the expression indicates all valid
or legal values for that column.
If yIf you want the scheduled job to run every minute, the expresion will be
in the form below.
* * * * *
The The expression below causes the scheduler to run the job at the fifth minute
of every ninth hour everyday.
5 9 * * *
To run a job every tenth minute of every hour from Monday to Friday only, the expression
will be in the form below.
10 * * * 1,2,3,4,5
You can read more on crontab expressions at
Deploying the Scheduled Job
After the application has been built and compiled, you can deploy the scheduled
job as a service by opening command prompt and change directory to where the
executable of the application is and then run the command.
To install the scheduled job as a service, and that is it !!!