为什么不是';不要重复Quartz时间表

本文关键字:Quartz 时间表 为什么不 | 更新日期: 2023-09-27 18:24:29

作业立即执行一次,但不会重复。我在这里做错了什么?

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Quartz;
using Quartz.Impl;
namespace QuartzConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var schedulerFactory = new StdSchedulerFactory();
            IScheduler scheduler = schedulerFactory.GetScheduler();
            scheduler.Start();
            var jobDetail = JobBuilder
                                .Create<SampleJob>()
                                .WithIdentity("myJob", "myGroup")
                                .Build();
            var trigger = TriggerBuilder
                                .Create()
                                .WithIdentity("myTrigger", "myGroup")
                                .WithSimpleSchedule(c => c.WithIntervalInSeconds(10))
                                .Build();
            scheduler.ScheduleJob(jobDetail, trigger);
            var stopwatch = new Stopwatch();
            stopwatch.Start();
            while (true)
            {
                Console.WriteLine("running for {0}", stopwatch.Elapsed.ToString());
                Thread.Sleep(TimeSpan.FromSeconds(10));
            }
        }
    }
    public class SampleJob : IJob
    {
        public void Execute(IJobExecutionContext context)
        {
            Console.WriteLine("Execute!");
        }
    }
}

为什么不是';不要重复Quartz时间表

尝试在计划中添加".ReatForever()"。