2014-11-05 57 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它应该工作。