Quartz.Net Trigger Scheduled On Demand

I have some Quartz.Net jobs that run on a schedule

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

Is it possible for me to manually run this task to start when I want?

Thus, it continues to work as usual, but in a certain piece of code, I can just run it off-schedule once or twice. But this does not affect the planned work?

+5
source share
1 answer

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

Yes, you can run this task as needed.

Use the void TriggerJob(JobKey jobKey) to do this, as shown below:

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

If you want to transfer some data to the task when it is executed on demand, you can also do this by simply using another overload void TriggerJob(JobKey jobKey, JobDataMap data); 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); 
+6
source

All Articles