Quartz实现定时job
static void Main(string[] args) { Task<IScheduler> tsk=StdSchedulerFactory.GetDefaultScheduler(); IScheduler Scheduler = tsk.Result; IJobDetail JobDetail = JobBuilder.Create<Job>().WithIdentity("完成").Build(); ITrigger trigger = TriggerBuilder.Create().WithIdentity("确认定时") .WithCronSchedule("0/5 * * * * ?").Build() as ITrigger; //每5s一次 Scheduler.ScheduleJob(JobDetail, trigger); Scheduler.Start(); Console.ReadKey(); }
public class Job : IJob { public async Task Execute(IJobExecutionContext context) { await Task.Run(() => { Console.WriteLine("123"); }); } }