开发者

SharePoint TimerJobs and threading

开发者 https://www.devze.com 2022-12-21 09:50 出处:网络
I\'ve written a SharePoint 2010 app that uses a TimerJob to trigger processing of some documents in a list. The timer is set to trigger every minute but the the processing may take more than a minute.

I've written a SharePoint 2010 app that uses a TimerJob to trigger processing of some documents in a list. The timer is set to trigger every minute but the the processing may take more than a minute. I'm just wondering if the next trigger of the timer job will be started using a new thread, or will the timer service just wait until the first thread has completed. I have no idea how Sharepoint manages threads for TimerJobs and I can't really find any relevant information.

This is possibly a problem given that my TimerJob definition has the following:

 public override void Execute(Guid contentDbId)
    {
        try
        {
            SPWebApplication webApplication = this.Parent as SPWebApplication;
            SPContentDatabase contentDb = webApplication.ContentDatabases[contentDbId];
            using (SPSite site = contentDb.Sites[0])
            {
                using (SPWeb web = site.RootWeb)
                {                       
                    PRManager.TriggerProcessing(web);    // ?                   
                }
            }
        }                      
        catch (Exception)
        { 
        }
    }
}

The PRManager.TriggerProcessing() is a static 开发者_StackOverflow中文版method, obviously, and while it does contain mechanisms to limit only one thread at a time entering the method body, I'm just wondering IF SharePoint does create multiple threads in the event that those at-minute-interval calls to execute overlap.


Well, it is not so much a "thread" thing as much as it is a "job" thing.

SharePoint stores all jobs in a database table and it uses this table to track what is running and where it is running. It has a built in synchronization engine that is responsible for making sure the jobs execute as the job instructions say.

For example take the deployment ask which is nothing more than a job. The deployment task only allows One job to run for a given solution at a time. It makes sure that all of the tasks finish on each server in the farm before the overall job is reported as done.

So the answer will depend on how your job configuration properties are set. There is a property on that job that tells SharePoint to only allow one instance of that job to run at a time. So if the job is currently executing another instance of it will not be started.

0

精彩评论

暂无评论...
验证码 换一张
取 消