简体   繁体   English

计划前更改Quartz.NET作业或触发器的名称

[英]Changing the name of a Quartz.NET job or trigger before scheduling

This is probably a simple question, but I am pretty new to using Quartz.NET, but how do you change the name of a job or trigger before scheduling? 这可能是一个简单的问题,但是我对使用Quartz.NET还是很陌生,但是如何在计划之前更改作业或触发器的名称? I am basically making a template job in a support class, and then using it in my main program that handles the scheduling. 我基本上是在支持类中制作模板作业,然后在处理计划的主程序中使用它。

Since I need unique names for each job/trigger, I was basically going to take the template job's name like "SomeJob" to "SomeJob01" when I copy it in to the main program for scheduling. 由于每个作业/触发器都需要唯一的名称,因此我将模板作业的名称复制到主程序中以进行调度时,基本上会将其名称从“ SomeJob”改为“ SomeJob01”。

This appears like it would be simple, but all I find when i search is people saying that you can't change job details after they have been scheduled, where this one is I am changing the name so that I CAN schedule them. 这看起来似乎很简单,但是我在搜索时发现的全部内容是,人们说您无法在安排好工作细节后再进行更改,这是我在更改名称以便可以进行工作安排。

In Quartz, a job is separate from its scheduling trigger. 在Quartz中,作业与其调度触发器是分开的。 You can add the same job with multiple triggers. 您可以使用多个触发器添加同一作业。

I'm not entirely sure I understand what you are doing with the job, but to add it to Quartz, you can do: 我不完全确定我了解您在做什么,但是要将其添加到Quartz中,您可以执行以下操作:

private const string DEFAULT_GROUP = "MyDefaultGroup";

Trigger trigger = TriggerUtils.MakeHourlyTrigger();

JobDetail jobDetail = new JobDetail("YourUniqueJobName", DEFAULT_GROUP, typeof(YourJobClass));

// now add the job to Quartz
scheduler.ScheduleJob(jobDetail, trigger);

In this manner you can either add a new job with a unique name and assign a new trigger to it, or you could assign a new trigger to an existing job. 这样,您可以添加具有唯一名称的新作业并为其分配新的触发器,也可以为现有作业分配新的触发器。

But generally speaking, to modify something in Quartz, you have to remove it, change your object, and then re-add it. 但是通常来说,要修改Quartz中的某些内容,您必须将其删除,更改对象,然后重新添加。

Here is an overview of jobs/triggers: http://quartznet.sourceforge.net/tutorial/lesson_2.html 以下是作业/触发器的概述: http : //quartznet.sourceforge.net/tutorial/lesson_2.html

Here is more information on how triggers work: http://quartznet.sourceforge.net/tutorial/lesson_4.html 以下是有关触发器如何工作的更多信息: http : //quartznet.sourceforge.net/tutorial/lesson_4.html

Here is more information on how jobs work: http://quartznet.sourceforge.net/tutorial/lesson_3.html 以下是有关工作方式的更多信息: http : //quartznet.sourceforge.net/tutorial/lesson_3.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM