防止立即触发Quartz.Net事件

时间:2011-04-26 22:19:56

标签: c# 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");
    }
}

1 个答案:

答案 0 :(得分:1)

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

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

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