Order of execution of events subscribed programatically

Order of execution of events subscribed programatically



When one subscribes an event programatically how does Sitecore determine the order of that event x the ones patched through configuration? Is there a way to control that?



For example when one opens the even item:created or item:saved it´s well known that if you register them through config it uses the order of config patched to execute but what if you subscribe an event programatically what does that mean? Which gets executed first and how to control that?



For example:


Sitecore.Events.Event.Subscribe("item:created", myArgs);



How does this event execution order relate to other item:created patched through configuration?



Update:
This code is triggered as part of a processor hooked into the initialize pipeline.





Do you have hook also configured for class that is calling this event subcription? How it is configured?
– Peter Procházka
Sep 4 '18 at 13:06





@PeterProchazka updated question description
– Diego
Sep 4 '18 at 13:24




2 Answers
2



The configuration would already be loaded to execute that pipeline. Your added events would normally get sent to the end of any existing events.



Keep in mind though, you should not rely on event ordering.



Do NOT rely on event ordering. All event dispatches should be logically independent, as if they were occurring in parallel. Events are logically independent actions.



https://stackoverflow.com/a/374549/81631



Agree with Mark, the only addition to that is that dynamic subscribed events are executed after events from configuration.



From Sitecore.Events.Event.RaiseEvent:


result = GetConfigSubscribers().RaiseEvent(eventName, parameters);
DynamicSubscribers.RaiseEvent(eventName, parameters, result);



Where DynamicSubscribers would contain your programatically bound events and the GetConfigSubscribers would contain the config bound events



Thanks for contributing an answer to Sitecore Stack Exchange!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)