1

I need to run job on 2 different schedules (morning and afternoon). I know how to run it on one schedule, but not sure how to set it so 2 schedules trigger this job

var saferWatchJobDetail = JobBuilder.Create<SaferWatchProcessor>().Build();
            var swtriggerMorning = TriggerBuilder.Create().WithCronSchedule("0 10 6 ? * MON-SUN *", cs => cs.InTimeZone(TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"))).Build();
            var swtriggerAfternoon = TriggerBuilder.Create().WithCronSchedule("0 10 13 ? * MON-FRI *", cs => cs.InTimeZone(TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"))).Build();
            this.scheduler.ScheduleJob(saferWatchJobDetail, swtriggerMorning);

According to documentation it seems like I need to use ScheduleJob override with ISet<ITrigger> but I'm not sure about 2 things:

  1. What is implementing ISet and how do I instantiate this object?
  2. What is other parameter replace? Not sure how should I use it. And what is the "key"? From documentation:

If any of the given job or triggers already exist (or more specifically, if the keys are not unique) and the replace parameter is not set to true then an exception will be thrown.

katit
  • 17,375
  • 35
  • 128
  • 256
  • 1
    Possible duplicate of [Multiple triggers of same Job Quartz.Net](http://stackoverflow.com/questions/35796696/multiple-triggers-of-same-job-quartz-net) – Set Aug 19 '16 at 09:25
  • http://stackoverflow.com/questions/35796696/multiple-triggers-of-same-job-quartz-net/35804345#35804345 See my answer – granadaCoder Aug 22 '16 at 17:21

1 Answers1

4

granaCoder's answer didn't work for me at all. It kept throwing exceptions. Not sure why.

If you want to use triggerset, which ended up working for me, this is how you do it:

        var triggerSet = new Quartz.Collection.HashSet<ITrigger>();
        var saferWatchJobDetail = JobBuilder.Create<SaferWatchProcessor>().Build();
        var swtriggerMorning = TriggerBuilder.Create().WithCronSchedule("0 10 6 ? * MON-SUN *", cs => cs.InTimeZone(TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"))).Build();
        var swtriggerAfternoon = TriggerBuilder.Create().WithCronSchedule("0 10 13 ? * MON-FRI *", cs => cs.InTimeZone(TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"))).Build();
        triggerSet.Add(swtriggerMorning);
        triggerSet.Add(swtriggerAfternoon);
        this.scheduler.ScheduleJob(saferWatchJobDetail, triggerSet, true);
Tjaart
  • 3,912
  • 2
  • 37
  • 61