开发者

SharePoint 2010 event listener - SPItemEventReceiver with multithreading

I have an event handler dll that implements SPItemEventReceiver. I like to run a background thread in this dll. The events are passed on to this background thread for processing so that the event handling methods won't block. SharePoint 2010 loads the dll but the thread does not start. I am not able to use the ThreadPool class as well. Is this a restriction imposed by SharePoint on external event handlers? How can I work around thi开发者_运维百科s?


Assuming that you're using 'post' events (ItemAdded, ItemUpdated), then you just have to register them as asynchronous mode. Then the event handler's events will run in their own threads, not blocking.

Beware of race conditions between your event handler and displaying your edit form (i.e. that your event handler updates your item after the edit form has been displayed).

SPEventReceiverDefinition eventReceiver = eventReceivers.Add();
eventReceiver.Name = receiverName;
eventReceiver.Synchronization = SPEventReceiverSynchronization.Asynchronous; 
eventReceiver.Type = SPEventReceiverType.ItemAdded;
eventReceiver.SequenceNumber = sequenceNumber; 
eventReceiver.Assembly = assemblyFullName ;
eventReceiver.Class = assemblyClassName ;
eventReceiver.Data = receiverData ;

eventReceiver.Update();

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.speventreceiverdefinition.synchronization.aspx

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜