在quartz.net
触发Execute(IJobExecutionContext context)
的一天中尝试标识触发器的首次执行和最后执行。有什么方法可以通过quartz.net
Execute(IJobExecutionContext context)
方法找到它?
答案 0 :(得分:0)
IEnumerable<DateTime> firingTimes = context.Trigger.GetNextFiringTimes(DateTimeOffset.Now.Date, DateTimeOffset.Now.Date.AddDays(1));
public static class TriggerExts
{
public static IEnumerable<DateTime> GetNextFiringTimes(this ITrigger trigger, DateTimeOffset? after = null, DateTimeOffset? before = null)
{
ITrigger temp = trigger.Clone();
after = after ?? DateTimeOffset.Now;
DateTimeOffset? next = temp.GetFireTimeAfter(after);
before = before ?? next.Value.AddYears(1);
while (next.HasValue && next.Value < before)
{
yield return next.Value.LocalDateTime;
next = temp.GetFireTimeAfter(next.Value);
}
}
}