I have below situation where, I have to prevent OnItemProcessed event from occuring more than once.
namespace Website
{
public class ItemEventHandler
{
public void OnItemProcessed(object sender, EventArgs args)
{
// Code here will be processed once for every item in that publish event.
if(condition){
Queue.WriteMessage();
}
// once message is written to Queue based on condition, this event handler should not be run for subsequent items in that publish event
}
}
}
events config patch
<sitecore>
<events>
<event name="publish:itemProcessed">
<handler type="Website.ItemEventHandler, Website" method="OnItemProcessed">
</handler>
</event>
</events>
</sitecore>
item:published
event? So you want to write to Queue only for the first item published? E.g. you publish item with 2 children, and you want to write to Queue only for the parent item, not for the children, correct?ItemEventHandler
class, and set it totrue
when the condition is satisfied. Then add another event handler onpublish:end
which will reset the variable back tofalse
. It should do the trick assuming that you have only 1 Sitecore instance publishing items at the same time and you're not using publishing service.