Skip to content
Amal Hashim
All posts
Snippet

SharePoint - Retrieve SharePoint Timer Job Schedule

A utility function that finds a timer job by name in the current web application and returns its schedule type.

This utility function looks through the job definitions of the current web application and returns the schedule type of the job with the given name.

csharp
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;
}

Example

csharp
string schedule = GetTimerJobStatus("My Custom Timer Job");
// e.g. "Microsoft.SharePoint.Administration.SPMinuteSchedule"

The returned name tells you whether the job runs on a minute, hourly, daily, weekly or monthly schedule.