簡體   English   中英

Quartz.net:在特定的時間間隔內運行作業

[英]Quartz.net: Run a job for specific interval of time

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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM