[英]Check if a SharePoint timer job is currently running
如何檢查某個WFE上當前是否正在運行SharePoint計時器作業? (當然是編程)。
我創建了一個控制台應用程序並嘗試放置一些代碼,但不確定它是否滿足您的要求:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
namespace SPTimerServices
{
class Program
{
static void Main(string[] args)
{
const string MY_SERVER = "spsvr";
var services = SPFarm.Local.Services;
foreach (SPService service in services)
{
if (service is SPWebService)
{
var webService = (SPWebService)service;
foreach (SPWebApplication webApp in webService.WebApplications)
{
foreach (SPJobDefinition job in webApp.JobDefinitions)
{
// Match with our server
if (job.Server != null && string.Compare(job.Server.Address, MY_SERVER, true) == 0)
{
// Console.WriteLine(job.Name);
foreach (var e in job.HistoryEntries)
{
if (e.Status == SPRunningJobStatus.Initialized)
{
Console.WriteLine(job.Name);
}
}
}
}
}
}
}
Console.WriteLine("Press any key to continue...");
Console.ReadLine();
}
}
}
上面的代碼不起作用,它只找到已完成和已中止的作業(因此“歷史記錄”)
以下是對正在運行的作業的檢查:
if (webapp.RunningJobs.Cast<SPRunningJob>().Any(curRunningJob => curRunningJob.JobDefinitionTitle.Equals(jobTitle)))
來自http://shareatsharepoint.blogspot.in/2012/11/finding-running-sharepoint-timer-job.html
使用PowerShell
CLS
Get-SPWebApplication | ForEach-Object {
$_.WebService.RunningJobs | select JobDefinitionTitle,ServerName,
StartTime,PercentageDone,status | Format-Table -autosize}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.