標籤:style blog http io ar color os sp for
官網:http://www.quartz-scheduler.net/
API:http://www.quartz-scheduler.net/documentation/index.html
快速入門:http://www.quartz-scheduler.net/documentation/quartz-2.x/quick-start.html
一個簡單的快速入門樣本
using Quartz.Impl;using System;using Quartz;using System.Threading;namespace QuartzTest1{ class Program { static void Main(string[] args) { try { Common.Logging.LogManager.Adapter = new Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter {Level = Common.Logging.LogLevel.Info}; // Grab the Scheduler instance from the Factory //從工廠的執行個體中擷取 發送器 IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler(); // and start it off scheduler.Start();//啟用發送器 // define the job and tie it to our HelloJob class定義一個job把它交給 HelloJob的類 IJobDetail job = JobBuilder.Create<HelloJob>() .WithIdentity("job1", "group1") //job的名稱 和 job所在的組 .Build();//建立這個job // Trigger the job to run now, and then repeat every 10 seconds //現在就觸發這個job,並沒隔10秒重複 ITrigger trigger = TriggerBuilder.Create() .WithIdentity("trigger1", "group1")//觸發器 名稱和 組 .StartNow() .WithSimpleSchedule(x => x .WithIntervalInSeconds(2) //這裡參數為”秒“ .RepeatForever()) .Build(); // Tell quartz to schedule the job using our trigger scheduler.ScheduleJob(job, trigger);//通知到quarts 調度這個job用觸發器 // some sleep to show what‘s happening //Thread.Sleep(TimeSpan.FromSeconds(60)); // and last shut down the scheduler when you are ready to close your program //scheduler.Shutdown();//關閉調度 } catch (SchedulerException se) { Console.WriteLine("錯誤記錄檔:"+se); } //Console.WriteLine("Press any key to close the application"); //Console.ReadKey(); } } public class HelloJob : IJob { public void Execute(IJobExecutionContext context) { Console.WriteLine("Greetings from HelloJob!-wjw"); } }}
Quartz.NET 快速入門