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() .WithIdentity("job1", "group1") .Build(); // 4.创建 trigger ITrigger trigger = TriggerBuilder.Create() .WithIdentity("trigger1", "group1") .WithCronSchedule(cron) .Build(); // 5.使用trigger规划执行任务job await sched.ScheduleJob(job, trigger); } } }