SPRunningJobCollection.GetInstance 方法
获取SPRunningJob对象的实例,或者如果该对象不存在,将引发异常。
命名空间: Microsoft.SharePoint.Administration
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
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
)
参数
jobDefinitionId
类型:System.Guid表示正在运行的作业的SPJobDefinition对象的Guid中。
serverName
类型:System.String
返回值
类型:Microsoft.SharePoint.Administration.SPRunningJob
表示此实例的SPRunningJob对象。
异常
异常 | 条件 |
---|---|
ArgumentOutOfRangeException | 无效的参数或作业已被删除。 |
备注
在几个服务器,可能有多个实例或每次作业可能被限制为场上的一个正在运行的实例。
示例
下面的代码示例循环访问SharePoint Foundation服务器场中,若要显示有关正在运行的每个服务,或尚未删除从SPRunningJobCollection与每个服务关联的每个作业的信息上的服务。对于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);
}
}