简体   繁体   中英

Quartz scheduler job not triggered?

I'm new to Quartz.net and trying a quick start example, some how it does not trigger anything to run.

     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)
            {

            }
        }
}

// console main

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

Your code is fine, but it is finishing before the job runs.

Change your main to:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM