C#:How to schedule multiple routine by Quartz.net at different time of the day once [duplicate]

蓝咒 提交于 2020-01-07 08:50:52

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!