使用 Quartz.Net 并需要相同的触发器来拥有多个日历,虽然这是不可能的,但我正在寻找有关如何实现类似功能的建议.
Using Quartz.Net and have a need for the same trigger to have multiple Calendars, whilst this isn't possible I'm looking for suggestions of how to achieve similar functionality.
例如,我想在 X 分钟内运行该作业,每天上午 9 点到 10 点除外,但可以根据需要在一天中的其他时间进行安排.
For example I want to run the job in X minutes and exlude 9-10am every day but be able to block out other times during the day as required.
下面的代码工作正常,但如果我想阻止另一个时间间隔,我看不到这样做的方法.
The code below works fine but if I want to block out another time interval I can't see a way of doing it.
ISchedulerFactory schedFact = new StdSchedulerFactory(); sched = schedFact.GetScheduler(); CronCalendar cronCal = new CronCalendar("* * 9 ? * * *"); sched.AddCalendar("testCal", cronCal, true, true); CronTrigger trigger = new CronTrigger("cronTrigger", null, "0 0/1 * 1/1 * ? *"); trigger.StartTimeUtc = DateTime.UtcNow.AddMinutes(10); trigger.CalendarName = "testCal"; JobDetail job = new JobDetail("testJob", null, typeof(DumbJob)); sched.ScheduleJob(job, trigger); sched.start();简单的测试工作:
public class DumbJob : IJob { public DumbJob() { } public void Execute(JobExecutionContext context) { MessageBox.Show("Dumb job is running"); } } 推荐答案您可以创建日历链.每个日历都可以有一个基准日历,在确定是否排除或包括给定时间时也会检查基准日历.查看 CronCalendar 的构造函数:
You can create a chain of calendars. Every calendar can have a base calendar which is also checked when determining whether given time is excluded or included. See CronCalendar's contructor:
public CronCalendar(ICalendar baseCalendar, string expression)更多推荐
Quartz.Net 多个日历
发布评论