Quartz.Net 按需触发预定作业
Quartz.Net Trigger Scheduled Job On Demand
我有一些 Quartz.Net 工作运行按计划
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?
是的,您可以在需要时触发此作业。
为此使用 void TriggerJob(JobKey jobKey)
方法,如下所示:
scheduler.TriggerJob(new Jobkey("MarkAsSolutionReminderJob"));
如果你想在按需执行作业时将一些数据传递给作业,你也可以通过使用与下面相同方法的另一个重载void TriggerJob(JobKey jobKey, JobDataMap data);
来实现:
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);
我有一些 Quartz.Net 工作运行按计划
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?
是的,您可以在需要时触发此作业。
为此使用 void TriggerJob(JobKey jobKey)
方法,如下所示:
scheduler.TriggerJob(new Jobkey("MarkAsSolutionReminderJob"));
如果你想在按需执行作业时将一些数据传递给作业,你也可以通过使用与下面相同方法的另一个重载void TriggerJob(JobKey jobKey, JobDataMap data);
来实现:
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);