系統:Win10
編譯器:VS2013
.Net版本:4.5
Quartz版本:2.3.3
Common.Logging.Core.dll
Common.Logging.dll
Quartz.dll
namespace QuartzNet.Jobs { public class JobGetNowTime : IJob { public void Execute(IJobExecutionContext context) { Console.WriteLine(DateTime.Now.ToString("yyy-MM-dd hh:mm:ss")); } } }
namespace QuartzNet { class Program { /// <summary> /// 以下程序的功能是:每秒鐘輸出當前時間,執行10次 /// </summary> /// <param name="args"></param> static void Main(string[] args) { //1.0創建調度工廠 ISchedulerFactory factory = new StdSchedulerFactory(); //2.0通過工廠獲取調度器實例 IScheduler scheduler = factory.GetScheduler(); //3.0通過JobBuilder構建Job IJobDetail job = JobBuilder.Create<JobGetNowTime>().Build(); //4.0通過TriggerBuilder構建Trigger ISimpleTrigger trigger = (ISimpleTrigger)TriggerBuilder.Create() .WithSimpleSchedule(a => a.WithIntervalInSeconds(1).WithRepeatCount(10)) .Build(); //5.0組裝各個組件<Job,Trigger> scheduler.ScheduleJob(job, trigger); //6.0啟動 scheduler.Start(); Thread.Sleep(10000); //7.0銷毀內置的Job和Trigger scheduler.Shutdown(true); Console.ReadKey(); } } }
http://blog.csdn.net/chenweitang123/article/details/37777399