gpt4 book ai didi

c# - Quartz.net:在特定时间间隔内运行作业

转载 作者:太空狗 更新时间:2023-10-30 00:51:23 26 4
gpt4 key购买 nike

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。

最佳答案

添加 EndingDailyAt调用:

ITrigger trigger = TriggerBuilder
.Create()
.WithDailyTimeIntervalSchedule(s =>
s.WithIntervalInMinutes(15)
.OnMondayThroughFriday()
.StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(9, 0))
.EndingDailyAt(TimeOfDay.HourAndMinuteOfDay(15, 0)))
.Build();

关于c# - Quartz.net:在特定时间间隔内运行作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28186044/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com