using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Quartz;
using Quartz.Impl;
using Quartz.Job;
using ConsoleApplication2;
namespace Lesson1
{
class Program
{
static void Main(string[] args)
{
//Create the scheduler factory
ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
//Ask the scheduler factory for a scheduler
IScheduler scheduler = schedulerFactory.GetScheduler();
//Start the scheduler so that it can start executing jobs
scheduler.Start();
// Create a job of Type WriteToConsoleJob
IJobDetail job = JobBuilder.Create(typeof(WriteToConsoleJob)).Build();
ITrigger trigger = TriggerBuilder.Create().WithDailyTimeIntervalSchedule(s => s.WithIntervalInMinutes(15).OnMondayThroughFriday().StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(9, 0))).Build();
scheduler.ScheduleJob(job, trigger);
//A nice way to stop the scheduler, waiting for jobs that are running to finish
scheduler.Shutdown(true);
}
}
}
我已经创建了一个测试工作,并且工作日的工作正常,从0900开始在15分钟后重复,但我想在特定的时间间隔运行它,即0900到1500小时。 而且我不想为此使用CronTrigger。
答案 0 :(得分:6)
添加EndingDailyAt来电:
ITrigger trigger = TriggerBuilder
.Create()
.WithDailyTimeIntervalSchedule(s =>
s.WithIntervalInMinutes(15)
.OnMondayThroughFriday()
.StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(9, 0))
.EndingDailyAt(TimeOfDay.HourAndMinuteOfDay(15, 0)))
.Build();