防止 Quartz.Net 事件立即起火
当我创建一个简单的触发器并将其分配给调度程序时,它会立即触发,然后按照计划的时间间隔再次触发。如何才能使其只在指定时间触发?
示例代码如下:
// construct a scheduler factory
ISchedulerFactory schedFact = new StdSchedulerFactory();
// get a scheduler
IScheduler sched = schedFact.GetScheduler();
// construct job info
JobDetail jobDetail = new JobDetail("myJob", "Default", typeof(DumbJob));
// Example trigger to fire after 1 minute, no repeat
Trigger trigger = TriggerUtils.MakeMinutelyTrigger(1, 0);
// Schedule the job
trigger.Name = "demoTrigger";
sched.ScheduleJob(jobDetail, trigger);
sched.Start();
public class DumbJob : IJob
{
public DumbJob()
{
}
public void Execute(JobExecutionContext context)
{
MessageBox.Show("Dumb job is running");
}
}
When I create a simple trigger and assign it to a scheduler, it fires immediately and then again at the scheduled interval. How can it be made to only fire at the specified time?
Example code below:
// construct a scheduler factory
ISchedulerFactory schedFact = new StdSchedulerFactory();
// get a scheduler
IScheduler sched = schedFact.GetScheduler();
// construct job info
JobDetail jobDetail = new JobDetail("myJob", "Default", typeof(DumbJob));
// Example trigger to fire after 1 minute, no repeat
Trigger trigger = TriggerUtils.MakeMinutelyTrigger(1, 0);
// Schedule the job
trigger.Name = "demoTrigger";
sched.ScheduleJob(jobDetail, trigger);
sched.Start();
public class DumbJob : IJob
{
public DumbJob()
{
}
public void Execute(JobExecutionContext context)
{
MessageBox.Show("Dumb job is running");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
触发器对象具有 StartTimeUtc 属性,您可以使用该属性指定触发器何时开始触发等。这是一个示例:
这将创建一个触发器,该触发器将在下一个偶数分钟开始触发。
The trigger object has a StartTimeUtc property which you can use to specify when the trigger will start firing and so on. Here is an example:
this creates a trigger that will start firing the next even minute.