官网:https://www.quartz-scheduler.net/
github:https://github.com/quartznet/quartznet/releases
参考例子:https://www.cnblogs.com/best/p/7658573.html
我用NuGet下载,本人是.net 4.0只能使用2.x.x版本
Grab it from NuGet
Install-Package Quartz
1、实现IJOB接口
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BLL
{
public class TestJob : IJob
{
public static string cron = "0 0 23 * * ?";//23点触发
public static Action Tick;
public void Execute(IJobExecutionContext context)
{
Tick();
}
}
}
2、创建调度器,把JOB添加到调度器,添加触发器,启动调度,暂停调度,关闭调度
//调度器
private IScheduler scheduler;
/// <summary>
/// 开始调度
/// </summary>
public void StartScheduler()
{
//1、调度器工厂
ISchedulerFactory factory;
//创建一个调度器
factory = new StdSchedulerFactory();
scheduler = factory.GetScheduler();
//2、创建一个任务
IJobDetail opcAcquisitionCompareItemJob = JobBuilder.Create<TestJob>().WithIdentity("job1", "group1").Build();
//3、创建一个触发器
ITrigger opcAcquisitionCompareItemTrigger = TriggerBuilder.Create()
.WithIdentity("trigger1", "group1")
.WithCronSchedule(OPCAcquisitionCompareItemJob.cron)
.Build();
//4、将任务与触发器添加到调度器中
scheduler.ScheduleJob(opcAcquisitionCompareItemJob, opcAcquisitionCompareItemTrigger);
scheduler.Start();
}
/// <summary>
/// 停止调度
/// </summary>
public void StopScheduler()
{
scheduler.PauseAll();
}
/// <summary>
/// 关闭调度
/// </summary>
public void shutdownScheduler()
{
scheduler.Shutdown();
}