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");

         });
     }
 }

 

posted @ 2024-02-23 09:27  萌橙  阅读(16)  评论(0编辑  收藏  举报