0
我有以下代碼來安排使用Quartz的重新啓動作業。該代碼爲每週的每一天設置觸發器(由用戶選擇)。所以這項工作應該能夠每天最多運行一次。但是,當我測試它時,它會連續運行三次而不是一次。有任何想法嗎?運行連續三次觸發的Quartz.net作業 - 應該只有一次
private void ScheduleJob(Server server)
{
bool jobScheduled = false;
JobDetail job = new JobDetail(server.ServerName, JOB_GROUP, typeof(RebootJob));
job.JobDataMap.Add("Server", server);
// Create a trigger for each day of the week on which this schedule falls
for(int i=0; i < 7; i++)
{
DayOfWeek dayOfWeek = (DayOfWeek)i;
DateTime? jobStartTime = server.GetNextScheduledRebootDateAndTime();
if(server.isScheduledOnDayOfWeek(dayOfWeek) && jobStartTime.HasValue)
{
SimpleTrigger trigger = new SimpleTrigger(
String.Format("{0}.{1}", server.ServerName, dayOfWeek.ToString()),
JOB_GROUP,
jobStartTime.Value.ToUniversalTime(),
null,
SimpleTrigger.RepeatIndefinitely,
TimeSpan.FromDays(7 * (double)server.RebootFrequency)
);
if(!jobScheduled)
{
ManagementService.Instance.Scheduler.ScheduleJob(job, trigger);
jobScheduled = true;
// Add server to list of servers with a reboot schedule
m_RebootableServers.Add(server.ServerName, server);
}
else // A job has already been schedule, just append triggers to it
{
trigger.JobName = job.Name;
trigger.JobGroup = job.Group;
ManagementService.Instance.Scheduler.ScheduleJob(trigger);
}
}
}
}
沒錯。在服務器對象中有另一個簽名爲'DateTime? GetNextScheduledRebootDateAndTimeAfter(System.DateTime)',我打算在這裏使用。我有點失望,我沒有聽清楚。謝謝一堆! – Trevor 2011-03-16 18:06:01