0
我現在使用quartz來重複執行任務,並且工作得很好。出於某種原因,我需要創建一個可以在兩天內運行的任務。下面是我所作的落實:石英作業在StartAt池啓動時執行()
IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
scheduler.Start();
IJobDetail jobWeekEnd = JobBuilderExtend.Create<CreateConsultationReplayJob>(() => new StandardContextProvider());
ITrigger triggerWeekend = TriggerBuilder.Create()
.WithIdentity("Foo", "Bar")
.WithCronSchedule("0 0 9 ? * SAT-SUN")
.ForJob(jobWeekEnd)
.Build();
scheduler.ScheduleJob(jobWeekEnd, triggerWeekend); // WORKS WELL
var jobNonWorkingDay = JobBuilderExtend.Create<CreateConsultationReplayJob>(() => new StandardContextProvider());
var trigger1 = TriggerBuilder.Create()
.WithIdentity("Foo2", "Bar")
.StartAt(new DateTimeOffset(new DateTime(2017, 04, 17, 09, 00, 00)))
.ForJob(jobNonWorkingDay)
.Build();
scheduler.ScheduleJob(jobNonWorkingDay, trigger1);
var jobNonWorkingDay2 = JobBuilderExtend.Create<CreateConsultationReplayJob>(() => new StandardContextProvider());
var trigger2 = TriggerBuilder.Create()
.WithIdentity("Foo3", "Bar3")
.StartAt(new DateTimeOffset(new DateTime(2017, 05, 01, 09, 00, 00)))
.ForJob(jobNonWorkingDay2)
.Build();
scheduler.ScheduleJob(jobNonWorkingDay2, trigger2);
TRIGGER1和觸發2似乎在正確的時間不觸發,但我每次回收池,並隨機,最後一次出現是在11時16分15秒。
任何線索我應該挖的地方?
好像你正在使用Quartz.NET,我編輯你的問題來設置正確的標記。 – walen
@walen感謝您的更新 –
嘗試在計劃作業後啓動您的計劃程序。 1)scheduler.ScheduleJob(...) 2)scheduler.Start(); – NikNik