防止 Quartz.Net 事件立即起火

发布于 2024-11-03 15:37:38 字数 795 浏览 2 评论 0原文

当我创建一个简单的触发器并将其分配给调度程序时,它会立即触发,然后按照计划的时间间隔再次触发。如何才能使其只在指定时间触发?

示例代码如下:

// 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

喵星人汪星人 2024-11-10 15:37:38

触发器对象具有 StartTimeUtc 属性,您可以使用该属性指定触发器何时开始触发等。这是一个示例:

     trigger.StartTimeUtc = TriggerUtils.GetEvenMinuteDate(DateTime.Now.AddMinutes(1));

这将创建一个触发器,该触发器将在下一个偶数分钟开始触发。

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:

     trigger.StartTimeUtc = TriggerUtils.GetEvenMinuteDate(DateTime.Now.AddMinutes(1));

this creates a trigger that will start firing the next even minute.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文