1、引用附件中的两个DLL
2、创建类
public class QuartzJob:IStatefulJob
{
private static ISchedulerFactory factory = null;
private static IScheduler scheduler = null;
/// <summary>
/// 启动任务
/// </summary>
public static void Start()
{
try
{
factory = new StdSchedulerFactory();
scheduler = factory.GetScheduler();
JobDetail job1 = new JobDetail("job1", "jobgroup1", typeof(QuartzJob), false, true, true);
CronTrigger trigger = new CronTrigger("trigger1", "group1", "job1", "jobgroup1", "0 0/1 * * * ?");
trigger.TimeZone = TimeZone.CurrentTimeZone;
scheduler.ScheduleJob(job1, trigger);
JobDetail job2 = new JobDetail("job2", "jobgroup2", typeof(QuartzJob), false, true, true);
trigger = new CronTrigger("trigger2", "group2", "job2", "jobgroup2", "0 0 8 * * ?");
trigger.TimeZone = TimeZone.CurrentTimeZone;
scheduler.ScheduleJob(job2, trigger);
scheduler.Start();
}
catch (Exception e)
{
}
}
/// <summary>
/// 停止任务
/// </summary>
public static void Stop()
{
scheduler.Shutdown(true);
}
/// <summary>
/// 暂停任务
/// </summary>
public static void Pause()
{
scheduler.PauseAll();
}
/// <summary>
/// 继续任务
/// </summary>
public static void Continue()
{
scheduler.ResumeAll();
}
/// <summary>
/// 任务执行体
/// </summary>
/// <param name="context"></param>
public void Execute(JobExecutionContext context)
{
try
{
if (context.Trigger.JobName == "job1")
{
}
if (context.Trigger.JobName == "job2")
{
}
}
catch (Exception ex)
{
}
}
}
3、调用方法
QuartzJob.Start();
4、点击下载附件