Avoid Chained Event Handlers
Hello AX Word,
Did you know that you can have a pre/post event handlers to an event handlers.
Probably it's not a good idea anyways, but I would like to show you how can you get into a chained event handlers problem. Not a rocket science though.
Create the following class.
It contains one method, and two event handlers.
The first event handler is subscribed to the method.
The second event handler is subscribed to the first event handler.
And to make life fun, the first event handler is also subscribed to the second event handler. Yes, you can have one event handler to multiple events.
We have got chained event handlers.
Let's see what is going to happen.
Create a runnable class and call the printLine method of the class TestA.
If you run this code you will get a Stack Overflow Exception. Obviously.
Be aware and take care!
Did you know that you can have a pre/post event handlers to an event handlers.
Probably it's not a good idea anyways, but I would like to show you how can you get into a chained event handlers problem. Not a rocket science though.
Create the following class.
It contains one method, and two event handlers.
The first event handler is subscribed to the method.
The second event handler is subscribed to the first event handler.
And to make life fun, the first event handler is also subscribed to the second event handler. Yes, you can have one event handler to multiple events.
We have got chained event handlers.
class TestA
{
public void printLine()
{
info("printLine");
}
[PreHandlerFor(classStr(TestA), methodStr(TestA, printLine)),
PreHandlerFor(classStr(TestA), staticMethodStr(TestA, printLineEventHandlerEventHandler))]
public static void printLineEventHandler(XppPrePostArgs _args)
{
info("Event handler 1");
}
[PreHandlerFor(classStr(TestA), staticMethodStr(TestA, printLineEventHandler))]
public static void printLineEventHandlerEventHandler(XppPrePostArgs _args)
{
info("Event handler 2");
}
}
Let's see what is going to happen.
Create a runnable class and call the printLine method of the class TestA.
If you run this code you will get a Stack Overflow Exception. Obviously.
Be aware and take care!
This was originally posted here.
*This post is locked for comments