Partager via


SPRunningJobCollection.GetInstance - Méthode

Obtient une instance d'un objet SPRunningJob , ou lève une exception si cet objet n'existe pas.

Espace de noms :  Microsoft.SharePoint.Administration
Assembly :  Microsoft.SharePoint (dans Microsoft.SharePoint.dll)

Syntaxe

'Déclaration
Public Function GetInstance ( _
    jobDefinitionId As Guid, _
    serverName As String _
) As SPRunningJob
'Utilisation
Dim instance As SPRunningJobCollection
Dim jobDefinitionId As Guid
Dim serverName As String
Dim returnValue As SPRunningJob

returnValue = instance.GetInstance(jobDefinitionId, _
    serverName)
public SPRunningJob GetInstance(
    Guid jobDefinitionId,
    string serverName
)

Paramètres

Valeur renvoyée

Type : Microsoft.SharePoint.Administration.SPRunningJob
Un objet SPRunningJob qui représente cette instance.

Exceptions

Exception Condition
ArgumentOutOfRangeException

Paramètre non valide, ou travail a vient d'être supprimée.

Remarques

Il peut y avoir plusieurs instances sur plusieurs serveurs, ou si la tâche peut être limitée à une instance en cours d'exécution sur la batterie de serveurs à la fois.

Exemples

L'exemple de code suivant itère les services sur une batterie de SharePoint Foundation pour afficher des informations sur chaque tâche qui s'exécute pour chaque service ou n'a pas encore été supprimée à partir de la SPRunningJobCollection associé à chaque service. Pour les objets SPRunningJob , toute interaction par programme est possédant des propriétés ; Il existe des méthodes disponibles de l'objet SPRunningJobCollection qui permettent à l'implémenteur d'interagir avec une instance spécifique d'un objet SPRunningJob .

[C#]

SPFarm farm = SPFarm.Local.Farm;
SPServiceCollection services = SPFarm.Local.Services;
int rand_job;
Guid jobdefid;
SPRunningJob rj;
string servername;
string svc_name = string.Empty;
 foreach (SPService service in services) {
  SPRunningJobCollection runningJobs = service.RunningJobs;
  if (runningJobs.Count > 0) {
    if (svc_name == string.Empty) {
       svc_name = service.Name;
    }
    Console.WriteLine("****Job Collection Count is     " + runningJobs.Count);
    Console.WriteLine("****Job Collection Service is   " + runningJobs.Service);
    // For the GetInstance method, save off job information at random
    rand_job = runningJobs.Count / 2;
    Console.WriteLine("****Collection member " + rand_job + " is " + runningJobs[rand_job].JobDefinition);
    jobdefid = runningJobs[rand_job].JobDefinitionId;
    servername = runningJobs[rand_job].ServerName;
  }
  else {
    jobdefid = Guid.Empty;
    servername = null;
  }
  foreach (SPRunningJob runningJob in runningJobs) {
    Console.WriteLine("****Job Id is           " + runningJob.JobDefinitionId);
  }
  if (jobdefid != Guid.Empty) {
    // random jobdef from collection 
    // getinstance method
    rj = runningJobs.GetInstance(jobdefid, servername);
    Console.WriteLine("*@@* Job Definition is   " + rj.JobDefinition);
    Console.WriteLine("*@@* Job Id is           " + rj.JobDefinitionId);
    Console.WriteLine("*@@* Job Title is        " + rj.JobDefinitionTitle);
  }
}

Voir aussi

Référence

SPRunningJobCollection classe

SPRunningJobCollection - Membres

Microsoft.SharePoint.Administration - Espace de noms

SPFarm