C# Quartz.Net 如何创建每天不增加 1 分钟的日程安排
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12735750/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Quartz.Net how to create a daily schedule that does not gain 1 minute per day
提问by Bittercoder
I am trying to build a repeating daily schedule in Quartz.Net but having a few issues:
我试图在 Quartz.Net 中建立一个重复的每日计划,但有一些问题:
First off, I build a daily schedule, repating at 12:45 Using Quartz.Net code like this:
首先,我建立了一个每日计划,在 12:45 重复使用 Quartz.Net 代码,如下所示:
var trigger = TriggerBuilder.Create()
.WithDailyTimeIntervalSchedule(s =>
s.OnEveryDay().StartingDailyAt(new TimeOfDay(13, 00)))
.Build();
var times = TriggerUtils.ComputeFireTimes(trigger as IOperableTrigger, null, 10);
foreach (var time in times) Console.WriteLine(time);
This is being executed in New Zealand, DST (so UTC+13:00)
这是在新西兰执行,夏令时(所以 UTC+13:00)
And the output I get is rather strange:
我得到的输出相当奇怪:
5/10/2012 1:00:00 p.m. +13:00
5/10/2012 12:01:00 a.m. +00:00
5/10/2012 12:02:00 a.m. +00:00
5/10/2012 12:03:00 a.m. +00:00
5/10/2012 12:04:00 a.m. +00:00
5/10/2012 12:05:00 a.m. +00:00
5/10/2012 12:06:00 a.m. +00:00
5/10/2012 12:07:00 a.m. +00:00
5/10/2012 12:08:00 a.m. +00:00
5/10/2012 12:09:00 a.m. +00:00
The first date/time is displayed using local timezone, then the rest are displayed with UTC, and each time value is incremented by 1 minute, and the date never changes.
第一个日期/时间使用本地时区显示,其余时间使用 UTC 显示,每个时间值增加 1 分钟,日期永远不会改变。
I feel like I might be missing something fundamental here with the daily time interval schedule, but I just don't know what it is?
我觉得我可能在每日时间间隔计划中遗漏了一些基本的东西,但我只是不知道它是什么?
Edit
编辑
As an update to do this, I have now switched to using a CRON expression based trigger:
作为更新,我现在切换到使用基于 CRON 表达式的触发器:
TriggerBuilder.Create()
.WithCronSchedule(string.Format("0 {0} {1} ? * *", 0, 13))
.Build();
And it gave me the results I would expect:
它给了我我期望的结果:
5/10/2012 12:00:00 a.m. +00:00
6/10/2012 12:00:00 a.m. +00:00
7/10/2012 12:00:00 a.m. +00:00
8/10/2012 12:00:00 a.m. +00:00
9/10/2012 12:00:00 a.m. +00:00
10/10/2012 12:00:00 a.m. +00:00
11/10/2012 12:00:00 a.m. +00:00
12/10/2012 12:00:00 a.m. +00:00
13/10/2012 12:00:00 a.m. +00:00
14/10/2012 12:00:00 a.m. +00:00
But I would still like to know why the DailyTimeIntervale schedule is not working...
但我仍然想知道为什么 DailyTimeIntervale 计划不起作用......
采纳答案by sgmoore
You aren't specifying the interval which happens to default to 1 minute, so it assumes you want to run the job every minute.
您没有指定默认为 1 分钟的间隔,因此它假定您希望每分钟运行一次作业。
Try
尝试
ITrigger trigger = TriggerBuilder.Create()
.WithDailyTimeIntervalSchedule
(s =>
s.WithIntervalInHours(24)
.OnEveryDay()
.StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(13, 0))
)
.Build();
The default should be to run every day, so the OnEveryDay() isn't really needed.
默认应该是每天运行,所以 OnEveryDay() 并不是真正需要的。
Not sure why you are seeing local and UTC, as all my times are displayed in UTC.
不知道为什么您看到的是本地和 UTC,因为我所有的时间都以 UTC 显示。
回答by Jürgen Steinblock
While WithIntervalInHourswill probably solve this and a cron like schedule is even more flexible, I want to share another solution: EndingDailyAfterCount(...)
虽然WithIntervalInHours可能会解决这个问题,并且像 cron 这样的时间表更加灵活,但我想分享另一个解决方案:EndingDailyAfterCount(...)
var trigger = TriggerBuilder.Create()
.WithDailyTimeIntervalSchedule(s => s
.OnEveryDay()
.StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(13, 00)))
.EndingDailyAfterCount(1))
.Build();

