How thread-safe are the event handlers?

 

How do the events work?

I followed the documentation, and it read that the events were sent into a queue. But I am often getting conflicts that indicate the events (custom events and timer events) severely interfere with the main thread. So, how the events are timed and processed with relation to the indicator/advisor thread, could any one educate me?

 
Ovo:

How do the events work?

I followed the documentation, and it read that the events were sent into a queue. But I am often getting conflicts that indicate the events (custom events and timer events) severely interfere with the main thread. So, how the events are timed and processed with relation to the indicator/advisor thread, could any one educate me?

Please, provide more info about your environment and event types. If, by any chance, you're using DLLs with message pumps, this may screw up all the things.
 
marketeer:
Please, provide more info about your environment and event types. If, by any chance, you're using DLLs with message pumps, this may screw up all the things.

I do not use anything like message pumps.

Example of conflict: While running OnDeinit(), a destructor of an object fires a custom event to the home chart, notifying other attached scripts. But the Event gets caught immediately by the firing script, and interrupts the destructor method, making total mess in the current OnDeinit() environment. Indicator ends up with a crash.

The workarround I use is catching events into a custom queue, without running the handlers. Then I process the queue in a batch in the end on OnCalculate() or discard them in OnDeinit().

Similar with OnTimer().

So I wonder if someone can enlighten how the event handling works, because the event is apparently not sent to the queue as the documentation reads.

Reason: