Quartz.Net 多个日历

编程入门 行业动态 更新时间:2024-10-28 14:25:09
本文介绍了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 多个日历

本文发布于:2023-11-05 21:09:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1561865.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   日历   Quartz   Net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!