石英:星期一到星期五总是重复工作

时间:2014-08-18 11:18:02

标签: .net quartz-scheduler quartz.net

我有下一个触发器:

var resumeTasksTrigger = TriggerBuilder.Create()
    .WithIdentity("ResumeTasksTrigger", "Tasks")
    .StartAt(DateBuilder.FutureDate(15, IntervalUnit.Second))
    .WithSchedule(
        DailyTimeIntervalScheduleBuilder
        .Create()
        .OnMondayThroughFriday())
    .Build();

这个触发器应该每周工作还是只工作一次?如果它是正确的,我无法弄清楚如何设置intifinity重复IScheduleBuilder

1 个答案:

答案 0 :(得分:0)

除非您指定结束日期,否则它将永远运行:

ITrigger resumeTasksTrigger = TriggerBuilder.Create()
    .WithIdentity("ResumeTasksTrigger", "Tasks")
    .StartAt(DateBuilder.FutureDate(15, IntervalUnit.Second))
    .EndAt(DateBuilder.FutureDate(10, IntervalUnit.Year))
    .WithSchedule(
        DailyTimeIntervalScheduleBuilder
        .Create()
        .OnMondayThroughFriday()
        .WithIntervalInMinutes(30)
        .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(10, 0))
        .EndingDailyAt(TimeOfDay.HourAndMinuteOfDay(12, 0))
        )
    .Build();

您可以使用此代码检查已定义触发器的所有计划:

    private static void GetNextXFireTimes(ITrigger trigger, int triggersCount)
    {
        Console.WriteLine(string.Format("List of next {0} schedules: ", triggersCount.ToString()));

        var dt = trigger.GetNextFireTimeUtc();

        using (var file = new System.IO.StreamWriter(@"E:\TEMP\Quartz.net.Log.Log"))
        {
            for (int i = 0; i < triggersCount; i++)
            {
                if (dt == null)
                    break;

                file.WriteLine(dt.Value.ToLocalTime().ToString());

                dt = trigger.GetFireTimeAfter(dt);
            }  
        }
    }