Good day!
I have a DLL in which the process std::jthread(…..) is called. This function call in OnInit . When calling this function from an MQL program, it is possible to set the execution frequency in seconds.
The termination of this function occurs after calling the monitorThread.request_stop() function.
I tried to set the call to this stop function in OnDeinit. But OnDeinit is never executed at all; the terminal freezes.
I added a button to the chart and code under it a call to the functions monitorThread.request_stop() , Sleep, and then ExpertRemove()
When the frequency for the std::jthread(...) function is set to 1 second, then with Sleep(700) before Expert Remove(), the program exits the chart correctly.
With lower value for Sleep some time delete sometime freez. With higher frequency also need bigger value for Sleep.
Is that mean the function OnDeinit can't be call until some DLL still work or there another issuze?
No. The DLL operates within the MetaTrader terminal process. It has nothing to do with any OnDeinit() etc. of any EA and it won´t unload it or release its memory. In general you should not rely on OnDeinit or destructors when you work with the MQL debugger. Whenever you press "Stop" or close the chart, OnDeinit or destructors wont be called properly.
When you consider working with DLLs who do any background jobs and when you need deinitialization, you need to hook the chart-window and catch the window-messages to ensure, your DLL code is informed. For that, you also need to establish a bridge to identify the charts where your DLL was applied to.
Its all possible, but not without creating a stable framework for your DLLs.
Not only with DLLs, OnDeinit and destructors are never reliable in MQL debugger. Closing the chart-window just like that is enough to disrupt the whole deinit/destruction process.
Solution is:
1. Hook the chart window in a DLL
2. In the hook you wait for WM_CLOSE. Set a flag to be read by MQL. Once WM_CLOSE was called, set the flag, unhook the chart.
3. Within MQL OnTimer you call the DLL frequently and check the flag. If true, call ExpertRemove()
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Good day!
I have a DLL in which the process std::jthread(…..) is called. This function call in OnInit . When calling this function from an MQL program, it is possible to set the execution frequency in seconds.
The termination of this function occurs after calling the monitorThread.request_stop() function.
I tried to set the call to this stop function in OnDeinit. But OnDeinit is never executed at all; the terminal freezes.
I added a button to the chart and code under it a call to the functions monitorThread.request_stop() , Sleep, and then ExpertRemove()
When the frequency for the std::jthread(...) function is set to 1 second, then with Sleep(700) before Expert Remove(), the program exits the chart correctly.
With lower value for Sleep some time delete sometime freez. With higher frequency also need bigger value for Sleep.
Is that mean the function OnDeinit can't be call until some DLL still work or there another issuze?