问题
i know how to fire my one routine every day at specific time of day. here is the code.
IScheduler sched = null;
//construct a scheduler factory
ISchedulerFactory schedFact = new StdSchedulerFactory();
//get a scheduler
sched = schedFact.GetScheduler();
sched.Start();
IJobDetail job = JobBuilder.Create<frmMain>()
.WithIdentity("Job", "group")
.Build();
ITrigger trigger = TriggerBuilder.Create()
.WithDailyTimeIntervalSchedule
(s =>
s.WithIntervalInHours(24)
.OnEveryDay()
.StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(19, 07))
)
.Build();
sched.ScheduleJob(job, trigger);
suppose now i am in scenario that i need to trigger many routine at different time of the day once.
say routine1 should fire at 08:00, routine2 should fire at 15:00 and routine2 should fire at 18:00
now give me suggestion how could i fire different routine at different time of the day. thanks
回答1:
Like stuartd stated, you need multiple triggers for your job(routine2). I would also suggest to use CronTrigger
instead of SimpleTrigger
. You can easily create a CronTrigger
with:
var trigger1 = TriggerBuilder.Create()
.WithDescription(name)
.WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(15, 0))
.Build();
var trigger2 = TriggerBuilder.Create()
.WithDescription(name)
.WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(18, 0))
.Build();
And then just schedule your job with the 2 triggers:
sched.ScheduleJob(job, trigger1);
sched.ScheduleJob(job, trigger2);
来源:https://stackoverflow.com/questions/42366684/chow-to-schedule-multiple-routine-by-quartz-net-at-different-time-of-the-day-o