1
votes

I am working on a SharePoint 2010 integration that has an SPItemEventReceiver for handling ItemAdded and ItemUpdated events for the Document library list. I have added a constructor to handle some initialization for the event receiver. In testing/debugging I have noticed that when my feature is activated (the feature containing this event receiver) my event receiver is initialized 12 times. I have been trying to figure out why the constructor is called 12 times and wondering if all 12 instances are going to be alive until the feature is deactivated or if I need to be careful as some of them may be garbage collected down the road. Anyone know why there are 12 and what their lifetime is?

4

4 Answers

1
votes

I wouldn't say the magic number 12 is relevant; it's just scaling for you. Regardless, SharePoint event receivers should not depend on singleton semantics. What's important is that for each unique event, you can be sure that only one of these event receivers will handle the event, unless you accidentally added 12 to the same list ;-)

-Oisin

0
votes

Droping 12 Files suing explorer view will cause such a affect.

0
votes

make sure to remove the event receiver on feature deactivating. This happens a lot in dev environments, as many people create their activated code in the feature activation, but not the deactivate code and end up with a bunch of receivers on a list, etc.

0
votes

You might also try creating static members in the class, that should get some of what you are after. You'd have to test it though, I can't promise that will work.