0

I use the code below and run C# application, Schedule starts fine. But when i press STOP schedule button for stopping the current schedule after 2 minute, It still calling the code i write in "ExecuteJob" class because end time is set to "After 5 minute". Please guide if any thing is wrong in code or i am missing any part for using Quartz Scheduler.

Here is my Code:

public static void Start()
{
    IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
    scheduler.Start();
    int counter = scheduler.GetCurrentlyExecutingJobs().Count;
    IJobDetail job = JobBuilder.Create<ExecuteJob>().WithIdentity(new JobKey("EmailCampaignJob", "CampaignGroup")).Build();

    ITrigger trigger = TriggerBuilder.Create()
        .WithIdentity("EmailCampaignnTrigger", "CampaignGroup")
        .WithDailyTimeIntervalSchedule
          (s =>
             s.WithIntervalInSeconds(30)
            .OnEveryDay()
            .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(0, 0)
            )
          ).EndAt(DateTime.Now.AddMinutes(5))
        .Build();

    scheduler.ScheduleJob(job, trigger);
}
public static void stop()
{
    IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();        
    scheduler.UnscheduleJob(new TriggerKey("EmailCampaignnTrigger", "CampaignGroup"));
    scheduler.DeleteJob(new JobKey("EmailCampaignJob","CampaignGroup"));
    scheduler.Clear();
}
walen
  • 7,103
  • 2
  • 37
  • 58
  • Check this thread out: https://stackoverflow.com/questions/13081385/is-it-possible-to-kill-a-current-running-quartz-job – Dimitri Aug 11 '17 at 13:42
  • Code is perfect actually i am testing this locally and call to "stop" function from Global.asax Application end function. Now this works for me as per my requirement. Thank u – Zeeshan Maqsood Aug 11 '17 at 16:13

0 Answers0