【发布时间】:2011-07-18 01:48:13
【问题描述】:
我正在使用 Quartz 来提取最新的任务(从另一个来源),然后将其作为作业添加,为每个任务创建触发器等。 - 简单。
但是,有时任务会发生变化(因此它们已经存在)。因此我想改变它(让我们说保持简单Description。下面的代码用给定的日期更新特定任务的描述。
private static void SetLastPull(DateTime lastPullDateTime)
{
var lastpull = sched.GetJobDetail("db_pull", "Settings");
if(lastpull != null)
{
lastpull.Description = lastPullDateTime.ToString();
}
else
{
var newLastPull = new JobDetail("db_pull", "Settings", typeof(IJob));
newLastPull.Description = lastPullDateTime.ToString();
var newLastPullTrigger = new CronTrigger("db_pull", "Settings", "0 0 0 * 12 ? 2099");
sched.ScheduleJob(newLastPull, newLastPullTrigger);
}
}
我假设在我做lastpull.Description = lastPullDateTime.ToString(); 之后我应该调用一些东西来保存对数据库的更改。 有没有办法在 Quartz 中做到这一点,还是我必须使用其他方式进行更新?
【问题讨论】:
-
解决了。我不得不去
sched.AddJob(lastpull, true)。非常反直觉。
标签: c# scheduled-tasks quartz.net