Quartz.net启动后不立即执行

Quartz.net启动后不立即执行

看了好多帖子说加这一句,多番尝试后还是立即执行了。

((CronTriggerImpl)jobTrigger).MisfireInstruction = MisfireInstruction.CronTrigger.DoNothing;

 

经过测试后,还需要加一行代码:

_scheduler.ResumeTrigger(jobTrigger.Key).Wait();

 

完整的代码如下:

                string jobname = Guid.NewGuid().ToString();
                JobKey jobKey = new JobKey(jobname);
                if (_scheduler.CheckExists(jobKey).Result)
                {
                    continue;
                }

                var job = JobBuilder.Create<HealthCheckJob>()
                   .WithIdentity(jobname)
                   .Build();
                job.JobDataMap.Add("Parm", item);

                var jobTrigger = TriggerBuilder.Create()
                    .WithIdentity(jobname)
                    .WithCronSchedule(item.ScheduleTime)      // Seconds,Minutes,Hours,Day-of-Month,Month,Day-of-Week,Year(optional field)
                    .ForJob(jobname)//作业名称
                    .Build();

                ((CronTriggerImpl)jobTrigger).MisfireInstruction = MisfireInstruction.CronTrigger.DoNothing;

                _scheduler.ScheduleJob(job, jobTrigger).Wait();

                _scheduler.ResumeTrigger(jobTrigger.Key).Wait();

 

posted @ 2024-02-05 13:41  小水皮  阅读(177)  评论(0编辑  收藏  举报