Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to write Custom Events so that event handlers are called on LIFO basis?
    primarykey
    data
    text
    <p>I want to create a few custom events, which will always call the registered event handlers in the reverse order of event registration i.e. most recently registered event handler is always called first. Is it possible? These events will be raised by Business Layer classes on certain error conditions, where registered event handlers may be able to overcome the error condition.</p> <p>Its a purely technical question, whether it is possible to do so or not? Is it possible to override the event chain call order? Does the language (any version of C# 2.0, 3.0, 4.0) support this feature or not? </p> <p><strong>EDIT:</strong></p> <p>The likely usage will be for error reporting and error recovery where possible. Example, Func A calls Func B which calls Func C. Func C may encounter an error condition and has an event for that. Func A and Func B would have registered for the event, if they are capable of providing an error recovery mechanism. Since Func B is more likely to have the context in which to solve the error, I want to call the most recent registered handler and check event args to see if error is resolved. If yes, I will not even call the other event handlers. If no, I will call the 2nd most recent registered handler, which will be the caller's caller function i.e. Func A.</p> <p>In most cases, code is usually structured in a way that if Func A calls Func B, then Func B does not call Func A i.e. cyclic calls are usually not there, and order of event handlers will be identical to order of function calls. So if Func A calls Func B which calls Func C, and Func C raises an "error event", the most suitable candidate to handle the error is Func B's event handler, followed by Func A's event handler and so on.</p> <p>Its like an unwinding of the stack trace and give the most recent caller function the opportunity to consume the event. Any no. of caller functions might be there.</p> <p>After the event has been consumed successfully by any handler, the Func C which raised the "error event" will proceed. It will check the Event args to determine this. If no handler has consumed the event, Func C will throw exception.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload