未触发 Quartz 调度程序作业?

Quartz scheduler job not triggered?

我是 Quartz.net 的新手,正在尝试一个快速入门示例,了解它如何不触发 运行 的任何内容。

     private static async Task RunProgramRunExample()
    {
        try
        {
            // Grab the Scheduler instance from the Factory
            NameValueCollection props = new NameValueCollection
            {
                { "quartz.serializer.type", "binary" }
            };
            StdSchedulerFactory factory = new StdSchedulerFactory(props);
            IScheduler scheduler = await factory.GetScheduler();

            // and start it off
            await scheduler.Start();

            IJobDetail job = JobBuilder.Create<ClothingJob>()
                .WithIdentity("clothing", "group1")
                .Build();

            ITrigger trigger = TriggerBuilder.Create()
                .WithIdentity("trigger1", "group1")
                .StartNow()
                .WithSimpleSchedule(x => x
                    .WithIntervalInSeconds(3)
                    .RepeatForever())
                .Build();

            // Tell quartz to schedule the job using our trigger
            await scheduler.ScheduleJob(job, trigger);

        }
        catch (SchedulerException se)
        {
            Console.WriteLine(se);
        }
    }


public partial class ClothingJob : IJob
    {
    public async Task Execute(IJobExecutionContext context)
        {
            try
            {                
                await Console.Out.WriteLineAsync("HelloJob is executing.");
            }
            catch (JobExecutionException ex)
            {

            }
        }
}

// 主控制台

static void Main(string[] args)
    {
        RunProgramRunExample().GetAwaiter().GetResult();
    }

您的代码没有问题,但它在作业运行之前就完成了。

将您的主要更改为:

static void Main(string[] args)
{
    RunProgramRunExample().GetAwaiter().GetResult();
    var name = Console.ReadLine();
}