Share via


SPService Class

Represents a farm-wide service.

Inheritance Hierarchy

System.Object
  Microsoft.SharePoint.Administration.SPAutoSerializingObject
    Microsoft.SharePoint.Administration.SPPersistedObject
      Microsoft.SharePoint.Administration.SPPersistedUpgradableObject
        Microsoft.SharePoint.Administration.SPService
          Microsoft.SharePoint.Administration.SPDiagnosticsService
          Microsoft.SharePoint.Administration.SPIncomingEmailService
          Microsoft.SharePoint.Administration.SPOutboundMailService
          Microsoft.SharePoint.Administration.SPWebService
          Microsoft.SharePoint.Administration.SPWindowsService

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

Syntax

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

Remarks

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.

Examples

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")

         job.Update()
      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");

         job.Update();
      }
   }
}

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

Reference

SPService Members

Microsoft.SharePoint.Administration Namespace