1

I have an Event Receiver that is attached to some change in a item list. This event receiver does things that consumes a lot of procedure. I want to run it under the process OWSTIMER.EXE and not W3WP.EXE, it seems that in Sharepoint 2013 the events receivers run under W3WP.EXE. I found this question because I wanted to do the same, but nobody answers. Because of that problem with the different process that I want to run under, I created a TimerJob this way that looks at the items on my list and does the same thing that before did the first event receiver. This is working, and is running under OWSTIMER.EXE the way I want. Now, the thing I want to do is, execute that TimerJob from my old event receiver (not the one I create to run this timerJob, like in the example), just because this list is not going to change frequently, and I want the process running, when it changes. (The thing I want, is hacking SharePoint to run an Event Receiver in OWSTIME.EXE)

Can I do that?

Thanks in advance.

in the example, the event receiver:

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;
            }
        }

my Event Receiver(that run onther 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?

            }
Community
  • 1
  • 1
Tupac
  • 647
  • 12
  • 37

2 Answers2

1

Answer is Yes and No, Yes because pro grammatically it is possible to run timer job using below code

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

No because, for using RunNow(), you need farm admin privilege.

And you cannot use RunWithElevatedPrivilages because When you use RunWithElevatedPrivileges method, the code runs in the context of application pool account, which usually does not have farm admin rights.

Mac
  • 6,991
  • 8
  • 35
  • 67
0

The SharePoint Work Item Timer Job could help you. Here can you find a example: http://sharepintblog.com/2011/12/12/spworkitemjobdefinition-a-different-kind-of-sharepoint-timer-job/