共用方式為


SPRunningJobCollection.GetInstance method

取得SPRunningJob物件的執行個體,或如果該物件不存在,會擲回例外狀況。

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

Syntax

'宣告
Public Function GetInstance ( _
    jobDefinitionId As Guid, _
    serverName As String _
) As SPRunningJob
'用途
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
)

參數

傳回值

Type: Microsoft.SharePoint.Administration.SPRunningJob
SPRunningJob 物件,代表此執行個體。

Exceptions

Exception Condition
ArgumentOutOfRangeException

剛已刪除 「 無效的參數或工作。

備註

可能有多個執行個體數個伺服器上,或一次,工作可能是限制在一部伺服器陣列上的執行個體。

Examples

下列程式碼範例會逐一顯示正在執行中每個服務,或尚未刪除從SPRunningJobCollection與每個服務相關聯的每個工作的相關資訊的SharePoint Foundation伺服器陣列上的服務。所有以程式設計方式進行互動是屬性 ; SPRunningJob物件,有可允許與SPRunningJob物件的特定執行個體互動執行者SPRunningJobCollection物件中的方法。

[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);
  }
}

請參閱

參照

SPRunningJobCollection class

SPRunningJobCollection members

Microsoft.SharePoint.Administration namespace

SPFarm