Created
July 19, 2012 18:08
-
-
Save srkirkland/3145733 to your computer and use it in GitHub Desktop.
quartz timer and trigger example
This file contains hidden or 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
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.Linq; | |
using System.Net; | |
using System.Threading; | |
using Microsoft.WindowsAzure; | |
using Microsoft.WindowsAzure.Diagnostics; | |
using Microsoft.WindowsAzure.ServiceRuntime; | |
using Microsoft.WindowsAzure.StorageClient; | |
using Quartz; | |
using Quartz.Impl; | |
namespace WorkerRole1 | |
{ | |
public class TraceJob : Quartz.IJob | |
{ | |
public void Execute(IJobExecutionContext context) | |
{ | |
Trace.WriteLine("Job executed at " + DateTime.Now.ToLongTimeString()); | |
} | |
} | |
public class WorkerRole : RoleEntryPoint | |
{ | |
public override void Run() | |
{ | |
// This is a sample worker implementation. Replace with your logic. | |
Trace.WriteLine("WorkerRole1 entry point called", "Information"); | |
while (true) | |
{ | |
Thread.Sleep(10000); | |
Trace.WriteLine("Working", "Information"); | |
} | |
} | |
public override bool OnStart() | |
{ | |
// Set the maximum number of concurrent connections | |
ServicePointManager.DefaultConnectionLimit = 12; | |
// For information on handling configuration changes | |
// see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357. | |
DoQuartz(); | |
return base.OnStart(); | |
} | |
public void DoQuartz() | |
{ | |
// create job | |
var jobDetail = JobBuilder.Create<TraceJob>().Build(); | |
// create trigger | |
var trigger = TriggerBuilder.Create().ForJob(jobDetail).WithSchedule(SimpleScheduleBuilder.RepeatSecondlyForever()).StartNow().Build(); | |
var dailyTrigger = TriggerBuilder.Create().ForJob(jobDetail) | |
.WithSchedule(DailyTimeIntervalScheduleBuilder.Create().StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(11, 03)).WithRepeatCount(0)) | |
.StartNow().Build(); | |
// get reference to scheduler (remote or local) and schedule job | |
var sched = StdSchedulerFactory.GetDefaultScheduler(); | |
sched.ScheduleJob(jobDetail, dailyTrigger); | |
sched.Start(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment