Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Is there a way to check for the status of a timer job, I need to know the last time it executed and its status, that it run correctly?

share|improve this question
    
This issue has been answered previously. [see this post][1] [1]: stackoverflow.com/questions/12120672/… –  Rahil Jan Muhammad Aug 29 '12 at 2:56

3 Answers 3

up vote 1 down vote accepted

You could try something like this:

SPWebApplication w = GetYourSPWebApplicationFromSomewhere();
foreach( var e in w.JobDefinitions["YourJobName"].HistoryEntries)
{
    var jobStatus = e.Status;
    var startTime = e.StartTime;
    // TODO: Do your stuff with Status and StartTime
}

var sc = SPFarm.Local.Services;
foreach (var e in sc["YourServiceName"].JobHistoryEntries)
{
    var jobStatus = e.Status;
    var startTime = e.StartTime;
    // TODO: Do your stuff with Status and StartTime
}
share|improve this answer

While Kjetil Gullen's and Paul Schaeflein solutions will work fine for completed tasks (succeeded or aborted for some reason), the entries for the currently running jobs are not yet present in the JobHistoryEntries.

You can include running jobs in your check by using the RunningJobs property of SPService (for all jobs running under a SharePoint service) or SPWebApplication (then the scope is limited to jobs running in web app). Code example for the first case is in StackOverflow's answer to "Check if a SharePoint timer job is currently running", and for the second case in SharePoint: list running timer jobs (C#) article.

share|improve this answer

SPWebApplication.JobHistoryEntries

SPService.JobHistoryEntries

share|improve this answer
    
example of working code you have? –  Esteban V Mar 30 '12 at 13:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.