2012-11-27 38 views
9

我正在使用Quartz.NET的C#中工作,並且在設置CronTrigger的失火指令時遇到問題。我正在運行安裝了Quartz DB的SQL後端。我有下面的代碼,它可以很好地用於創建作業和運行調度程序。Quartz.NET設置錯誤指示

IScheduler _scheduler; 
IJobDetail job; 
ISchedulerFactory sFactory; 
ICronTrigger trig; 

sFactory = new StdSchedulerFactory(); 

_scheduler = sFactory.GetScheduler(); 
_scheduler.Start(); 

job = JobBuilder.Create<Test>().WithIdentity("testJob", "testGroup").Build(); 
trig = (ICronTrigger) TriggerBuilder.Create().WithIdentity("testTrigger", "testGroup").WithCronSchedule("0/10 * * * * ?").Build(); int i = trig.MisfireInstruction; 

_scheduler.ScheduleJob(job, trig); 

我可以訪問的唯一misfireinstruction是trig.MisfireInstruction這是一個int,我不能對它進行設置。 在CronScheduleBuilder中也有一些函數WithMisfireHandlingInstruction

+0

'MisfireInstruction.CronTrigger.FireOnceNow'可能是我正在尋找...? –

+0

我編輯了你的標題。請參閱:「[應該在其標題中包含」標籤「](http://meta.stackexchange.com/questions/19190/)」,其中的共識是「不,他們不應該」。 –

+0

謝謝,對不起! –

回答

15

你觸發創作應該是這樣的:

trig = (ICronTrigger)TriggerBuilder 
     .Create() 
     .WithIdentity("testTrigger", "testGroup") 
     .WithCronSchedule("0/10 * * * * ?", x => x.WithMisfireHandlingInstructionFireAndProceed()) 
     .Build(); 

您可以使用這些選項:

  • WithMisfireHandlingInstructionDoNothing
  • WithMisfireHandlingInstructionFireAndProceed
  • WithMisfireHandlingInstructionIgnoreMisfires

你可以找到一個很好的解釋here

+0

完美,這正是我所需要的。 謝謝! –

+0

(我投了票,但我還沒有足夠的代表) –

+0

很高興我幫了忙。你總是可以在未來投票給我---)乾杯。 – LeftyX