Quartz.Net 多个日历 [英] Quartz.Net multiple calendars

查看:29
本文介绍了Quartz.Net 多个日历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 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 多个日历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆