2014-11-05 74 views
0

我想改變我的工作之一的觸發器。所以我正在做的是先看看我的工作是否有與之相關的觸發器。如果是這樣,我用Reschedule用戶選擇了一個新的觸發器。但是當我看着我的AdoJobStore時,新的觸發器不存在,重新計劃後作業將停止運行。工作重新安排不起作用

我已經把這個整個代碼在try-catch塊,但我沒有收到任何Exception S,但是這是也許是因爲我應該抓住JobExecutionException!而非只是Exception S'

var jobKey = new JobKey(jobName, jobGroup); 
IScheduler sched = scheduler.GetScheduler(); 
IList<ITrigger> triggers = sched.GetTriggersOfJob(jobKey); 
if (triggers.Count != 0) 
{ 
    ITrigger existingTrigger = triggers[0]; 
    sched.UnscheduleJob(existingTrigger.Key); 
    ITrigger newTrigger = BuildTrigger(triggerName, triggerGroup); 
    IJobDetail job = sched.GetJobDetail(jobKey); 
    DialogResult dr = MsgBox.Show(string.Format("Confirm campaign '{0}' with the schedule '{1}'?", lblCampaignName.Text, txtbxMessage.Text), "Confirm Schedule", MsgBox.Buttons.YesNo, MsgBox.Icon.Question); 
    if (dr == DialogResult.Yes) 
    { 

     sched.RescheduleJob(existingTrigger.Key, newTrigger); 
     int updateResult = UpdateCampaignSchedule(); 
     if (updateResult == 1) 
      MsgBox.Show("Campaign schedule successfully updated!", "Edit schedule", MsgBox.Buttons.OK, MsgBox.Icon.Info); 
     else 
      MsgBox.Show("Unable to update campaign schedule in the database.", "Edit schedule", MsgBox.Buttons.OK, MsgBox.Icon.Error); 
    } 
} 
else 
{ 
.. 
} 

回答

0

這是因爲打電話sched.UnscheduleJob(existingTrigger.Key。這會從作業存儲中刪除觸發器。因此,當調用sched.RescheduleJob(existingTrigger.Key, newTrigger)時,石英無法找到舊觸發器以將其替換爲新觸發器(如果查看返回值,它將爲空),也不會拋出異常,除非您的新觸發器無效。

刪除sched.UnscheduleJob(existingTrigger.Key, newTrigger它應該工作。