Domanda

I am working on a share-point 2010 custom list event receiver(item adding, item updating,item added), once in a while i will notice that when i create a new item, it seems like the event receiver wont fire but then in the list there will be entries for the created By column and the Created Column...how can i make the event receiver to fire all the time, or else if not is there a way to throw an error on the page when the event receiver is not fried, so that the user will know that the ticket is not being generated(and then prevent the columns(createdBy and the Created columns) to be added to the list when the event is not fired

È stato utile?

Soluzione

There is no way to act when an event is not triggered. That would sort of go against the logic of event handlers.

As per your other thread, you might have a code error in your event receiver, causing it to throw an exception and exit unfinished.

You might also have concurrency issues. Are you disabling event triggers while you are executing them (SPEventReceiverBase.EventFiringEnabled)? That will prevent events from being handled until you set Firing back to true. It will prevent any events (in the current thread) in any list until you set it back (see How DisableEventFiring / EventFiringEnabled works).

Best practice #1: If you disable event firing in your event handler, use a try-catch-finally block and re-enable them in your finally part. You might be leaving them disabling if you exit on an exception.

Best practice #2: Event handlers should be very short, especially the parts where you are disabling event firing. Especially asynchronous events.

Best practice #3: For nicer event cohabitation, implement your own event-type-specific event firing-disabling boolean (e.g. put a static bool in your event's class, and at the start of your event check if it's true or false before proceeding)

Best practice #4: You should not instantiate SPWeb or SPSite objects inside event handlers (other than SPItemEventProperties.Web) (ref)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top