SPService Class

Represents a farm-wide service.

Inheritance Hierarchy


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 _
    Inherits SPPersistedUpgradableObject

Dim instance As SPService
[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.

Dim services As SPServiceCollection = SPFarm.Local.Services
Dim myDateTime = New DateTime(2007, 1, 28)
Dim service As SPService

For Each service In  services
Dim runningJobs As SPRunningJobCollection = service.RunningJobs
Dim runningJob As SPRunningJob

   For Each runningJob In  runningJobs

      If runningJob.Status = SPRunningJobStatus.Failed AndAlso runningJob.StartTime > myDateTime Then
         Dim job As SPJobDefinition = runningJob.JobDefinition

         job.Schedule = SPSchedule.FromString("every 5 minutes between 0 and 59")

      End If
   Next runningJob
Next service
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");


Thread Safety

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

See Also


SPService Members

Microsoft.SharePoint.Administration Namespace