1

我有一个Event Receiver附加到项目列表中的一些更改。这个事件接收器会做一些消耗大量过程的事情。我想在进程下运行它OWSTIMER.EXE而不是W3WP.EXE,似乎在Sharepoint 2013事件接收器下运行W3WP.EXE。我发现这个问题是因为我想做同样的事情,但没有人回答。由于我想要运行的不同进程的问题,我创建了TimerJob 一种查看列表中的项目并执行与之前第一个事件接收器相同的操作的方法。这是有效的,并且正在运行OWSTIMER.EXE我想要的方式。现在,我想做的是,从我的旧事件接收器(不是我创建来运行这个 timerJob 的那个,就像在示例中一样)执行那个 TimerJob,只是因为这个列表不会经常改变,我想要进程运行,当它改变时。(我想要的东西是破解SharePoint运行Event Receiverin OWSTIME.EXE

我可以这样做吗?

提前致谢。

在示例中,事件接收器:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SPWebApplication parentWebApp = (SPWebApplication)properties.Feature.Parent;
                    SPSite site = properties.Feature.Parent as SPSite;
                    DeleteExistingJob(JobName, parentWebApp);
                    CreateJob(parentWebApp);
                });
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

我的Event Receiver(继续运行w3wp.exe):

    public override void ItemUpdated(SPItemEventProperties properties)
            {
                base.ItemAdded(properties);
                //here it does the same that do the Timer Job(but with that item)
                //here I want to execute my TimerJob. This is possible?

            }
4

2 回答 2

1

答案是“是”和“否”,是的,因为在编程上可以使用以下代码运行计时器作业

var yourjob = (from jobDefinition in WebApp.JobDefinitions
                                where jobDefinition.DisplayName == "oyu job name"
                                select jobDefinition).SingleOrDefault();
if (yourjob != null)
{
   yourjob.RunNow();
}

不,因为要使用 RunNow(),您需要农场管理员权限。

并且您不能使用 RunWithElevatedPrivilages,因为当您使用 RunWithElevatedPrivileges 方法时,代码在应用程序池帐户的上下文中运行,该帐户通常没有农场管理员权限。

于 2015-12-11T07:04:32.857 回答
0

SharePoint 工作项计时器作业可以帮助您。在这里你能找到一个例子: http ://sharepintblog.com/2011/12/12/spworkitemjobdefinition-a-different-kind-of-sharepoint-timer-job/

于 2016-01-01T15:51:46.327 回答