如何检查某个WFE上当前是否正在运行SharePoint计时器作业? (当然是编程)。
答案 0 :(得分:2)
我创建了一个控制台应用程序并尝试放置一些代码,但不确定它是否满足您的要求:
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();
}
}
}
答案 1 :(得分:1)
您可能需要探索工作历史记录。请看一下这些链接。
https://sharepoint.stackexchange.com/questions/32968/timer-job-programatically-check-status
答案 2 :(得分:1)
上面的代码不起作用,它只找到已完成和已中止的作业(因此为“历史记录”)
以下是对正在运行的作业的检查:
if (webapp.RunningJobs.Cast<SPRunningJob>().Any(curRunningJob => curRunningJob.JobDefinitionTitle.Equals(jobTitle)))
来自http://shareatsharepoint.blogspot.in/2012/11/finding-running-sharepoint-timer-job.html
答案 3 :(得分:1)
使用PowerShell
CLS
Get-SPWebApplication | ForEach-Object {
$_.WebService.RunningJobs | select JobDefinitionTitle,ServerName,
StartTime,PercentageDone,status | Format-Table -autosize}