1.安装Quartz包
2.编写Job任务
继承 IJob编辑自定义任务
3.调用job,以指定时间策略执行
定时600s执行一次
StdSchedulerFactory factory = new StdSchedulerFactory();
IScheduler scheduler = await factory.GetScheduler();
await scheduler.Start();
// 定义一个作业并关联触发器
IJobDetail job = JobBuilder.Create<SmsReportJob>()
.WithIdentity("smsReport", "group1")
.Build();
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("trigger1", "group1")
.WithSimpleSchedule(x => x.WithIntervalInSeconds(600).RepeatForever())
.Build();
await scheduler.ScheduleJob(job, trigger);
如果只执行一次的话这样即可
var trigger = TriggerBuilder.Create()
.WithSimpleSchedule(x => x.WithIntervalInSeconds(5).WithRepeatCount(0))
.Build();
Cron表达式下节详细介绍