views:

179

answers:

0

We have a problem with the scheduling of our timer jobs. The jobs we have developed run only one time after that they delete themselves. To schedule the jobs we filter the web application's SPJobDefinitionCollection for our timer job type and look for the one with the latest schedule time via the NextOccurrence() method of the job's Schedule property.

Then we uses the DateTime object we retrieved form the step before to calculate the schedule for the next job we'll create. As the DateTime object is of the type local time we transform it to UTC before we start the calculation. When we create and add the job to the web application the schedule start time is transformed back to local time before it is passed to the SPOneTimeSchedule constructor.

During our test runs we realized that the jobs don't start at the expected time. There should only be some minutes between the start time of each job, but we have several hours. After double checking our calculations we were looking at the DateTime object's we use as start parameter for our calculations and also at the DateTime objects we pass to the SPOneTimeSchedule constructor.

And here we realized some strange behavior. As far as we know the DateTime object passed to the SPOneTimeSchedule constructor should be of the kind local time. Internally SharePoint then transforms this value to UTC before storing it in the db. When a job is retrieved from the db the schedule information is transformed back from UTC to local time.

In contrast to this the schedule time of the jobs we retrieve form the SPJobDefinitionCollection is of the type unspecified, but it shows the local time. Transforming this DateTime object to an UTC DateTime object changes nothing about the time it self, it only changes the Kind property form unspecified to UTC and this leads to our scheduling problem.

So why is the schedule time of all the job's we created of the type unspecified although it should be local time? At the moment I don't see what we are doing wrong as we pass the time for the schedule in local time format.