0

I need retrieve via code, what's the schedule configuration of a Timerjob. Exe: for a Timerjob scheduled weekly, to get the value "weekly".

2 Answers 2

1
var spFarm = SPFarm.Local;
var timerJob = spFarm.TimerService.JobDefinitions.OfType<SPJobDefinition>().FirstOrDefault(n => n.Name == "Timer Job Name");

and then take a look at timerJob.Schedule object.

1
  • No meant about the Timejob that is current running. I should not iterate any TimerJob in Farm
    – hello B
    Apr 20, 2015 at 13:12
0

Try below function

string GetTimerJobStatus(string timerJobName) 
{
    string schedule = string.Empty;

    SPSecurity.RunWithElevatedPrivileges(() => 
    { 
        SPWebApplication webApp = SPContext.Current.CurrentWeb.WebApplication;
        foreach (SPJobDefinition job in webApp.JobDefinitions)
        {
            if (job.Name.Equals(timerJobName))
            {
                schedule = job.Schedule.GetType().FullName;
                break;
            }
        }
    });

    return schedule;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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