1
我是Quartznet調度程序的新手。我正試圖實施 「CalendarIntervalTriggerImpl」觸發器。我設置了一個通過日期(在2010年的一天 )觸發器。Job.Execute在通過StartTimeUTC調度作業時立即觸發
當我通過傳遞Jobdetail &觸發器調用ScheduleJob方法時,它立即觸發Job.Execute方法。我是否 缺少任何東西。請以正確的方式指導我。
請看下面的示例代碼,
class Program
{
private static IScheduler _scheduler;
static void Main(string[] args)
{
Console.WriteLine(DateTime.Now.Day);
ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
_scheduler = schedulerFactory.GetScheduler();
_scheduler.Start();
AddJob();
}
public static void AddJob()
{
IJob myJob = new MyJob(); //This Constructor needs to be parameterless
JobDetailImpl jobDetail = new JobDetailImpl("Group1", "Group1", myJob.GetType());
CalendarIntervalTriggerImpl trigger = new CalendarIntervalTriggerImpl("Group1", "Group1", IntervalUnit.Week, 2);
trigger.StartTimeUtc = DateTime.Now.AddDays(-3).AddSeconds(15);
_scheduler.ScheduleJob(jobDetail, trigger);
Console.WriteLine("Next : {0}", trigger.GetNextFireTimeUtc().Value.ToLocalTime());
}
}
internal class MyJob : IJob
{
public void Execute(IJobExecutionContext context)
{
Console.WriteLine("Executing the job...");
}
}