Last active
January 3, 2016 11:29
-
-
Save yemrekeskin/8456266 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// nuget package http://www.nuget.org/packages/Quartz/ | |
// http://www.quartz-scheduler.net/ | |
public class SampleJob | |
: IJob | |
{ | |
public void Execute(IJobExecutionContext context) | |
{ | |
Console.WriteLine("OK"); | |
} | |
} | |
public class SampleJobExecuter | |
{ | |
public virtual void Run() | |
{ | |
// Scheduler | |
// First we must get a reference to a scheduler | |
ISchedulerFactory schedulerFactory = new StdSchedulerFactory(); | |
IScheduler scheduler = schedulerFactory.GetScheduler(); | |
// Job | |
IJobDetail job = JobBuilder.Create<SampleJob>() | |
//.WithIdentity("jobx", "groupx") | |
.Build(); | |
// Trigger | |
// http://www.quartz-scheduler.org/documentation/quartz-2.2.x/tutorials/crontrigger to CronSchedule | |
ICronTrigger trigger = (ICronTrigger)TriggerBuilder.Create() | |
.WithIdentity("triggerx1", "groupx1") | |
.WithCronSchedule("0/10 * * * * ?") | |
.Build(); | |
scheduler.ScheduleJob(job, trigger); | |
scheduler.Start(); | |
try | |
{ | |
// wait five minutes to show jobs | |
Thread.Sleep(10000); | |
// executing... | |
} | |
catch (ThreadInterruptedException) | |
{ | |
} | |
scheduler.Shutdown(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment