Benjamins Blog

Benjamin Wegner über Weisheiten, SharePoint und IT Zeugs

Benjamins Blog header image 2

SPDailySchedule Execution Occurence

Oktober 20th, 2007 ·

Creating a timerjob via API is quite simple! It saves you creating a scheduled task as it was in SPS2003 required.


When using the SPDailySchedule you have to remember that it would not be enouth to just set the starttime. You have to set the endtime additionally. The effective execution will be calculated based on a randomized value between the start- and the endtime.


Check the reflector:






public override DateTime NextOccurrence(DateTime dt)
{
DateTime dtRound = new DateTime(0x7d4, 1, 1, this.m_lBeginHour, this.m_lBeginMin, this.m_lBeginSec);
dt = base.RoundToHour(dt, dtRound);
if (this.IsFixed)
{
return dt;
}
dtRound = new DateTime(0x7d4, 1, 1, this.m_lEndHour, this.m_lEndMin, this.m_lEndSec);
DateTime dtEnd = base.RoundToHour(dt, dtRound);
return base.RandomizeOccurrence(dt, dtEnd);
}


Therefore set  BeginHour, BeginMinute, BeginSecond, EndHour, EndMinute and EndSecond as required.

It is the same for:
SPMinuteSchedule
SPHourlySchedule
SPDailySchedule
SPMonthlySchedule
SPWeeklySchedule
SPYearlySchedule

Tags: Allgemein