Quartz.Net Trigger Scheduled Job On Demand

quartz-schedulerquartz.net

I have some Quartz.Net jobs which are running on a Schedule

scheduler.ScheduleJob(
new JobDetailImpl("MarkAsSolutionReminderJob", typeof(MarkAsSolutionReminderJob)),
new CalendarIntervalTriggerImpl("MarkAsSolutionReminderJobTrigger", IntervalUnit.Hour, 6));

Is it possible for me to manually trigger this Job to run when I want it to?

So it continues to run as normal, but in a specific piece of code I might want to just run it out of schedule once or twice. But it doesn't affect the scheduled job?

Best Answer

Is it possible for me to manually trigger this Job to run when I want it to?

Yes, you can trigger this job as and when you need.

Use void TriggerJob(JobKey jobKey) method for this as below:

scheduler.TriggerJob(new Jobkey("MarkAsSolutionReminderJob"));

If you want to pass some data to the job while executing it on demand, you can also do that by just using another overload void TriggerJob(JobKey jobKey, JobDataMap data); of the same method as below:

Dictionary<string, string> data = new Dictionary<string, string>();
//populate dictionary as per your needs
JobDataMap jobData = new JobDataMap(data);
scheduler.TriggerJob(new Jobkey("MarkAsSolutionReminderJob"),jobData);
Related Topic