Download MetaTrader 5

How thread-safe are the event handlers?

To add comments, please log in or register
Publish programs in Code Base. Improve your rating!
Ex Ovo Omnia
3145
Ex Ovo Omnia 2014.10.14 15:43 

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?

Stanislav Korotky
17876
Stanislav Korotky 2014.10.14 15:48  
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.
Ex Ovo Omnia
3145
Ex Ovo Omnia 2014.10.14 18:40  
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.

To add comments, please log in or register