Multiple triggers of same Job Quartz.NET

前端 未结 1 594
生来不讨喜
生来不讨喜 2020-12-17 15:56

I have the following code:

 IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
            scheduler.Start();
            IJobDetail job = Job         


        
相关标签:
1条回答
  • 2020-12-17 16:04

    Add the Job to the Scheduler.

    Then on the creation of the triggers, use ForJob.

    The code below is tested.

    IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
    
    
    //// scheduler.DeleteJob(new JobKey("J_Email"));
    
    
    IJobDetail job = JobBuilder.Create<MyConcreteJob>().StoreDurably().WithIdentity("J_Email", "J_Mailing").Build();
    
    scheduler.AddJob(job, true /* bool replace */ ); /* Add the given IJob to the Scheduler - with no associated ITrigger.  */
    
    
    ITrigger trigger = TriggerBuilder.Create()
                        .WithIdentity("MailTrigger1", "T_Mail1")
                        .StartNow()
                        .WithSimpleSchedule(x => x.WithMisfireHandlingInstructionIgnoreMisfires()
                            .WithIntervalInSeconds(3)
                            .RepeatForever())
                        .ForJob(job)
                        .Build();
    
    
    ITrigger triggernew = TriggerBuilder.Create()
                       .WithIdentity("MailTrigger", "T_Mail")
                       .StartNow()
                       .WithSimpleSchedule(x => x.WithMisfireHandlingInstructionIgnoreMisfires()
                           .WithIntervalInSeconds(5)
                           .RepeatForever())
                       .ForJob(job)
                       .Build();
    
    
    scheduler.ScheduleJob(triggernew);
    scheduler.ScheduleJob(trigger);
    
    scheduler.Start();
    
    0 讨论(0)
提交回复
热议问题