0

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

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!");
        }
    }
}
4

1 回答 1

1

尝试在时间表上添加“.RepeatForever()”。

于 2013-07-23T08:14:32.837 回答