You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1020 B
C#

using Quartz;
using Quartz.Impl;
using System.Configuration;
using System.Threading.Tasks;
namespace ZJ_BYD.Untils
{
public class QuartzHelper
{
private static string cron = ConfigurationManager.AppSettings["cron"];
public async static Task Start()
{
// 1.创建scheduler的引用
ISchedulerFactory schedFact = new StdSchedulerFactory();
IScheduler sched = await schedFact.GetScheduler();
//2.启动 scheduler
await sched.Start();
// 3.创建 job
IJobDetail job = JobBuilder.Create<MyJob>()
.WithIdentity("job1", "group1")
.Build();
// 4.创建 trigger
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("trigger1", "group1")
.WithCronSchedule(cron)
.Build();
// 5.使用trigger规划执行任务job
await sched.ScheduleJob(job, trigger);
}
}
}