gpt4 book ai didi

c# - 使用 Unschedulejob 修改触发器详细信息 - 我做错了什么? ( quartz 网)

转载 作者:行者123 更新时间:2023-11-30 17:20:45 25 4
gpt4 key购买 nike

我正在为我正在创建的系统使用 Quartz.NET,其中作业通过 Windows 服务运行,并且可以在 ASP.NET 页面中添加和编辑(包括触发器详细信息)。

不过我遇到了一些问题 - 我需要能够修改触发器的详细信息,例如 simpletrigger 的类型或 cronexpression,并且我被告知我需要取消计划作业然后重新安排它。问题是,取消安排工作然后重新安排是出于某种原因完全从工作中删除触发器。这是我在编辑页面上单击提交按钮时的代码:

 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);

知道为什么这不起作用吗?谢谢

新:

 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);

}


}

最佳答案

  • 我怀疑 UnscheduleJob 是否必要。改期应该delete the old 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);
    }

    你是说也许

        foreach (CronTrigger trigger in triggers.OfType<CronTrigger>())
    {
    trigger.CronExpressionString = txtCron.Text;
    sched.UnscheduleJob(trigger.Name, trigger.Group); //I would remove this
    sched.RescheduleJob(trigger.Name, trigger.Group, trigger);
    }
  • 最后,我会尝试使用触发器而不是修改旧触发器来重新安排

关于c# - 使用 Unschedulejob 修改触发器详细信息 - 我做错了什么? ( quartz 网),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4010048/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com