Hi all, I'm using Quartz.NET for a system I am creating, where jobs are run via a Windows Service and can be added and editted (inlcuding trigger details) in an ASP.NET page.
I'm having some issues though - I need to be able to modify a triggers details, such as the type of simpletrigger or the cronexpression, and I've been told that I need to unschedule the job then reschedule it. Problem is, unscheduling the job then rescheduling is totally removing the trigger from the job for some reason. Here is my code for when the Submit button is clicked on the edit page:
Trigger[] triggers = sched.GetTriggersOfJob(hdnID.Value, hdnGroupID.Value);
if (ddlScheduleType.SelectedIndex == 1)
{
sched.UnscheduleJob(triggers[0].Name, triggers[0].Group);
foreach (SimpleTrigger trigger in triggers.OfType<SimpleTrigger>())
{
if (ddlInterval.SelectedIndex == 0)
{
trigger.RepeatInterval = TimeSpan.Parse("00:00:01");
}
else if (ddlInterval.SelectedIndex == 1)
{
trigger.RepeatInterval = TimeSpan.Parse("00:01:00");
}
else if (ddlInterval.SelectedIndex == 2)
{
trigger.RepeatInterval = TimeSpan.Parse("01:00:00");
}
sched.RescheduleJob(trigger.Name, trigger.Group, trigger);
}
}
else
{
foreach (CronTrigger trigger in triggers.OfType<CronTrigger>())
{
trigger.CronExpressionString = txtCron.Text;
sched.UnscheduleJob(triggers[0].Name, triggers[0].Group);
sched.RescheduleJob(trigger.Name, trigger.Group, trigger);
}
}
sched.AddJob(jobDetail, true);
Any ideas why this isn't working? Thanks
NEW:
if (ddlScheduleType.SelectedIndex == 1)
{
foreach (SimpleTrigger trigger in triggers.OfType<SimpleTrigger>())
{
Trigger newtrigger = new SimpleTrigger();
if (ddlInterval.SelectedIndex == 0)
{
newtrigger = TriggerUtils.MakeSecondlyTrigger();
}
else if (ddlInterval.SelectedIndex == 1)
{
newtrigger = TriggerUtils.MakeMinutelyTrigger();
}
else if (ddlInterval.SelectedIndex == 2)
{
newtrigger = TriggerUtils.MakeHourlyTrigger();
}
newtrigger.Name = triggers[0].Name;
newtrigger.Group = triggers[0].Group;
newtrigger.JobName = triggers[0].JobName;
newtrigger.JobGroup = triggers[0].JobGroup;
sched.RescheduleJob(trigger.Name, trigger.Group, newtrigger);
}
}
else
{
foreach (CronTrigger trigger in triggers.OfType<CronTrigger>())
{
CronTrigger newtrigger2 = new CronTrigger();
newtrigger2.Name = trigger.Name;
newtrigger2.Group = trigger.Group;
newtrigger2.JobName = trigger.JobName;
newtrigger2.JobGroup = trigger.JobGroup;
newtrigger2.CronExpressionString = txtCron.Text;
sched.RescheduleJob(trigger.Name, trigger.Group, newtrigger2);
}
}