简体   繁体   中英

Quartz.NET StartNow not working together with WithDailyTimeIntervalSchedule

            ITrigger trigger = TriggerBuilder.Create()
                                .WithIdentity("trigger1", "group1")
                                .WithDailyTimeIntervalSchedule(x => x
                                    .WithIntervalInHours(2)
                                    .OnEveryDay()
                                    .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(8, 0))
                                    .EndingDailyAt(TimeOfDay.HourAndMinuteOfDay(23, 00)))
                                .StartNow()
                                .Build();

The problem with the above code is that StartNow is not working. It runs normally but only after 2 hours. I can't run it immediately.

StartNow is working with WithSimpleSchedule but not with .WithDailyTimeIntervalSchedule

Looks like WithDailyTimeIntervalSchedule is not what you need. If you specify start time = 8 AM, end time = 11 PM, interval = 2 hours, jobs will be scheduled to run exactly at 8 AM, 10 AM, 12 PM, 2 PM, 4 PM, 6 PM, 8 PM and 10 PM.

As a solution you can create two triggers:

  1. If the current time is between 8 AM and 11 PM, create trigger that fires now, now + 2 hours, now + 4 hours and stops today at 11 PM.
  2. The second trigger will fire at 8 AM, 10 AM, etc. starting from the next 8 AM time point (today or tomorrow).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM