一个简单的快速入门示例



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");
}
}
}