Export (0) Print
Expand All

SPService Class

Windows SharePoint Services 3

Represents a farm-wide service.

Namespace:  Microsoft.SharePoint.Administration
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

[GuidAttribute("DACA2A15-B9B5-43da-BEA3-6B75FBE3A883")]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
public class SPService : SPPersistedUpgradableObject

To return the parent service of a service instance, use the Service property of the SPServiceInstance class. Use the Services property of the SPFarm class to return an SPServiceCollection object that represents the collection of services on the server farm. Use an indexer to return a single service from the collection. For example, if the collection is assigned to a variable named myServices, use myServices[index] in C#, or myServices(index) in Visual Basic, where index is either the GUID or the name that identifies the service.

The following example iterates through the running jobs of all services on the server farm and modifies the schedule of jobs that failed and that started after a specified date.

SPServiceCollection services = SPFarm.Local.Services;

System.DateTime myDateTime = new DateTime(2007,1,28);

foreach (SPService service in services)
{
   SPRunningJobCollection runningJobs = service.RunningJobs;

   foreach (SPRunningJob runningJob in runningJobs)
   {

      if (runningJob.Status == SPRunningJobStatus.Failed && runningJob.StartTime > myDateTime)
      {
         SPJobDefinition job = runningJob.JobDefinition;
         job.Schedule = SPSchedule.FromString("every 5 minutes between 0 and 59");

         job.Update();
      }
   }
}

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

ADD
Show:
© 2014 Microsoft