3

How can I check if a SharePoint timer job is currently running on one of the WFEs ? (Programatically of course).

4

4 回答 4

2

上面的代码不起作用,它只能找到已完成和中止的作业(因此是“历史”)

以下对正在运行的作业进行检查:

if (webapp.RunningJobs.Cast<SPRunningJob>().Any(curRunningJob => curRunningJob.JobDefinitionTitle.Equals(jobTitle)))

来自http://shareatsharepoint.blogspot.in/2012/11/finding-running-sharepoint-timer-job.html

于 2013-06-12T10:20:42.247 回答
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();    
        }
    }
}
于 2012-08-25T16:24:13.460 回答
1

使用 PowerShell

CLS

Get-SPWebApplication | ForEach-Object {
    $_.WebService.RunningJobs | select JobDefinitionTitle,ServerName,
        StartTime,PercentageDone,status | Format-Table -autosize}
于 2014-08-04T10:35:41.050 回答