public class JobSchedulerWork_Test { public static async void GetMESData() { //调度器工厂 ISchedulerFactory Work = new StdSchedulerFactory(); //调度器 IScheduler schedulers_work = await Work.GetScheduler(); await schedulers_work.GetJobGroupNames(); /*-------------计划任务代码实现------------------*/ //创建任务 IJobDetail job_Work = JobBuilder.Create<DataTesst>() .WithIdentity("TimeGetDataTest", "TimeGroupEMSTest") .Build(); //创建触发器 每11点55分执行 //ITrigger TimeGetMESData = TriggerBuilder.Create().WithCronSchedule("0 55 11 * * ?").WithIdentity("TimeGetDataTest", "TimeGroupEMSTest").Build(); //每五秒执行一次 ITrigger TimeGetMESData = TriggerBuilder.Create().WithIdentity("TimeGetDataTest", "TimeGroupEMSTest").WithCronSchedule("0/5 * * * * ?").Build();
//每9秒执行一次 //ITrigger TimeGetMESData = TriggerBuilder.Create().WithIdentity("TimeGetDataTest", "TimeGroupEMSTest").WithSimpleSchedule(t => t.WithIntervalInSeconds(90000).RepeatForever()).Build(); //添加任务及触发器至调度器中 await schedulers_work.ScheduleJob(job_Work, TimeGetMESData); /*-------------计划任务代码实现------------------*/ //启动 await schedulers_work.Start(); } }
学习 Quartz.NET 待完善