Schedule Quartz.NET trigger that executes once a week

邮差的信 提交于 2019-12-24 11:26:30

问题


I need to schedule Quartz.NET trigger so that it fires on every Monday at 09.00. So, I tried to use some features as below but I think it does not true as the parameters are not logical (It worked for daily scheduling, but after change to this it does not). So, could you please give an example that executes job weekly?

ITrigger trigger = TriggerBuilder.Create()
    .WithDailyTimeIntervalSchedule
    (s =>
        s.WithInterval(1, IntervalUnit.Week)
        .OnDaysOfTheWeek(DayOfWeek.Monday)
        .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(9, 0))
     )
     .Build();

scheduler.ScheduleJob(job, trigger);

回答1:


ITrigger trigger= TriggerBuilder.Create()
             .WithIdentity("trigger1", "group1")
            .WithSchedule(CronScheduleBuilder.CronSchedule("0 0 9 ? * MON")).Build();

scheduler.ScheduleJob(job, trigger);

Please try the above code. Here, I am passing a parameter "0 0 9 ? * MON" by which the trigger will be fired Monday at 09.00.

For reference click here http://www.quartz-scheduler.org/documentation/quartz-2.x/tutorials/crontrigger.html



来源:https://stackoverflow.com/questions/34026183/schedule-quartz-net-trigger-that-executes-once-a-week

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!