今天遇到一个问题,调度器在启动时没法马上开始执行任务,代码以下:ui
var trigger = TriggerBuilder.Create() .StartNow() //此处无效 .WithCronSchedule("0 0/30 10-20 * * ?") .Build();
F12 能够看到 StartNow() 注释以下:this
// // 摘要: // Set the time the Trigger should start at to the current moment - the trigger // may or may not fire at this time - depending upon the schedule configured // for the Trigger. // // 返回结果: // the updated TriggerBuilder public TriggerBuilder StartNow();
在 stockoverflow 上查找结果以下spa
由上述得知,当使用 Cron 表达式时,StartNow 方法不会起任何效果,Cron 有其本身的执行时间。目前看来 StartNow 应该只适用于 SimpleTrigger 触发器。blog
解决方法:get
1.如上图,增长一个仅有 StartNow 的触发器来马上触发 Jobit
2.可在 scheduler.Start() 启动前手动调用执行 Job 一次io