Tuesday 6 December 2016

SharePoint Timer Job Run Mechanisms

If you want to run it every TEN MINUTES,use SPMinuteSchedule class to configure:
SPMinuteSchedule minSchedule = new SPMinuteSchedule();
minSchedule.BeginSecond = 0;
minSchedule.EndSecond = 5;
minSchedule.Interval = 10;
tempJob.Schedule = minSchedule;
tempJob.Update();


If you want to run it at 11:05 PM every day, use SPDailySchedule class to configure:
SPDailySchedule tempSchedule = new SPDailySchedule();
tempSchedule.BeginHour = 23;
tempSchedule.BeginMinute=5;
tempSchedule.BeginSecond = 0;
tempSchedule.EndSecond = 15;
tempSchedule.EndMinute = 5;
tempSchedule.EndHour = 23;
tempJob.Schedule = schedule;
tempJob.Update();


If you want to run it on the 1st of every month between 1:15am to 1:30am, use SPMonthlySchedule
SPMonthlySchedule schedule = new SPMonthlySchedule();
schedule.BeginDay = 1;
schedule.EndDay = 1;
schedule.BeginHour = 1;
schedule.EndHour = 1;
schedule.BeginMinute = 15;
schedule.EndMinute = 30;
tempJob.Schedule = schedule;
tempJob.Update();

If you want to run on Monday every week between 2:01:00 am to 2:01:05 am, use SPWeeklySchedule
SPWeeklySchedule schedule = new SPWeeklySchedule();
schedule.BeginDayOfWeek = DayOfWeek.Monday;
schedule.BeginHour = 2;
schedule.BeginMinute = 1;
schedule.BeginSecond = 0;
schedule.EndSecond = 5;
schedule.EndMinute = 1;
schedule.EndHour = 2;
schedule.EndDayOfWeek = DayOfWeek.Monday;
tempJob.Schedule = schedule;
tempJob.Update();


If you want to run it every year on Jan 23 at 9:05AM, use SPYearlySchedule
SPYearlySchedule JobSchedule = new SPYearlySchedule();
JobSchedule.BeginMonth = 1;
JobSchedule.EndMonth = 1;
JobSchedule.BeginDay = 23;
JobSchedule.EndDay = 23;
JobSchedule.BeginHour = 9;
JobSchedule.EndHour = 9;
JobSchedule.BeginMinute = 5;
JobSchedule.EndMinute = 5;
JobSchedule.BeginSecond = 0;
JobSchedule.EndSecond = 5;
tempJob.Schedule = schedule;
tempJob.Update();

Owstimer.exe is the worker process to debug the code.

No comments:

Post a Comment