graceful shutdown of services / eas

 
While using external DLL in services / eas when they are stopped the terminal can freeze when in middle of external calculations.
Are there any concepts of graceful shutdown, like a function in the .mq5 script that can handle this?
 

EAs that are properly coded to be event driven and not use eternal loops, will close properly.

For loops that might take longer, then the EA should check IsStopped or _StopFlag on every iteration and promptly return and exit.

DLLs should be coded to be event driven as well and not be stuck in long processing cycles.

Documentation on MQL5: Checkup / IsStopped
Documentation on MQL5: Checkup / IsStopped
  • www.mql5.com
IsStopped - Checkup - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
Fernando Carreiro #:

EAs that are properly coded to be event driven and not use eternal loops, will close properly.

For loops that might take longer, then the EA should check IsStopped or _StopFlag on every iteration and promptly return and exit.

DLLs should be coded to be event driven as well and not be stuck in long processing cycles.

Thank you seems straightforward . Btw. the error type is  of Hang type: Cross-thread

 
Fernando Carreiro #:

EAs that are properly coded to be event driven and not use eternal loops, will close properly.

For loops that might take longer, then the EA should check IsStopped or _StopFlag on every iteration and promptly return and exit.

DLLs should be coded to be event driven as well and not be stuck in long processing cycles.

Sorry for double post making sure you get the notification.

Returns true, if the _StopFlag system variable contains a value other than 0. A nonzero value is written into _StopFlag, if a mql5 program has been commanded to complete its operation. In this case, you must immediately terminate the program, otherwise the program will be completed forcibly from the outside after 3 seconds.

Forcibly completed is not clear here for me. If my program is stuck shouldn't the thread be killed in a manner that does not freeze my terminal?
Regards

 
ama bamo #: Forcibly completed is not clear here for me. If my program is stuck shouldn't the thread be killed in a manner that does not freeze my terminal?

The flag refers to MQL programs and indicates that it has been requested to stop, and the program is given 3 seconds to do a clean-up before they are forcefully closed.

As for the DLLs, it is up to the MQL program to handle them, and hopefully the DLLs were coded in a way that allows them to be interrupted and not be stuck in a loop. In other words, they should work asynchronously and not block.

 
Fernando Carreiro #:

The flag refers to MQL programs and indicates that it has been requested to stop, and the program is given 3 seconds to do a clean-up before they are forcefully closed.

As for the DLLs, it is up to the MQL program to handle them, and hopefully the DLLs were coded in a way that allows them to be interrupted and not be stuck in a loop. In other words, they should work asynchronously and not block.

Thanks again!
To be honest I cannot find much information about DLL resolving order, caveats tricks etc. For example some of my libraries have no problem to be found by MQL5 in the Editor but when ran from the terminal they cannot be found. It mostly happens when they have 3rd party DLL dependency. Even that the dependency can be loaded from MQL5 it still cannot be found by the terminal. I had to use process monitor to find a path where terminal is looking for the DLLS. It is looking in the main folder of the terminal.exe for example: Even that the dependency DLL can be loaded from MQL5 and is included in Libraries folder. Sorry for being a little chaotic it's time for me.

The best place to place DLL dependencies for your DLLS  that are imported in MQL5 is to place them in the terminal root folder ( i hope i didn't miss any documentation stating that clearly hahaha )

19:16:16.0298404        terminal64.exe  29504   RegQueryKey     HKLM\SOFTWARE\Microsoft\Fusion\PublisherPolicy\Default  SUCCESS Query: HandleTags, HandleTags: 0x100
19:16:16.0298582        terminal64.exe  29504   RegOpenKey      HKLM\SOFTWARE\Microsoft\Fusion\PublisherPolicy\Default\v4.0_policy.8.0.MyLibrary__b03f5f7f11d50a3a      NAME NOT FOUND  Desired Access: Read
19:16:16.0298740        terminal64.exe  29504   RegQueryKey     HKLM\SOFTWARE\Microsoft\Fusion\PublisherPolicy\Default  BUFFER TOO SMALL        Query: Name, Length: 0
19:16:16.0298873        terminal64.exe  29504   RegQueryKey     HKLM\SOFTWARE\Microsoft\Fusion\PublisherPolicy\Default  SUCCESS Query: Name
19:16:16.0299025        terminal64.exe  29504   RegOpenKey      HKLM\SOFTWARE\Microsoft\AppModel\Lookaside\machine\SOFTWARE\Microsoft\Fusion\PublisherPolicy\Default\v4.0_policy.8.0.MyLibrary__b03f5f7f11d50a3a        NAME NOT FOUND  Desired Access: Read
19:16:16.0299197        terminal64.exe  29504   RegQueryKey     HKLM\SOFTWARE\Microsoft\Fusion\PublisherPolicy\Default  SUCCESS Query: HandleTags, HandleTags: 0x100
19:16:16.0299295        terminal64.exe  29504   RegOpenKey      HKLM\SOFTWARE\Microsoft\Fusion\PublisherPolicy\Default\policy.8.0.MyLibrary__b03f5f7f11d50a3a   NAME NOT FOUND  Desired Access: Read
19:16:16.0299400        terminal64.exe  29504   RegQueryKey     HKLM\SOFTWARE\Microsoft\Fusion\PublisherPolicy\Default  BUFFER TOO SMALL        Query: Name, Length: 0
19:16:16.0299497        terminal64.exe  29504   RegQueryKey     HKLM\SOFTWARE\Microsoft\Fusion\PublisherPolicy\Default  SUCCESS Query: Name
19:16:16.0299615        terminal64.exe  29504   RegOpenKey      HKLM\SOFTWARE\Microsoft\AppModel\Lookaside\machine\SOFTWARE\Microsoft\Fusion\PublisherPolicy\Default\policy.8.0.MyLibrary__b03f5f7f11d50a3a     NAME NOT FOUND  Desired Access: Read
19:16:16.0300490        terminal64.exe  29504   FASTIO_NETWORK_QUERY_OPEN       C:\Windows\Microsoft.Net\assembly\GAC_64\MyLibrary\v4.0_8.0.0.0__b03f5f7f11d50a3a\MyLibrary.dll FAST IO DISALLOWED      
19:16:16.0300860        terminal64.exe  29504   IRP_MJ_CREATE   C:\Windows\Microsoft.Net\assembly\GAC_64\MyLibrary\v4.0_8.0.0.0__b03f5f7f11d50a3a\MyLibrary.dll PATH NOT FOUND  Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
19:16:16.0301469        terminal64.exe  29504   FASTIO_NETWORK_QUERY_OPEN       C:\Windows\Microsoft.Net\assembly\GAC_MSIL\MyLibrary\v4.0_8.0.0.0__b03f5f7f11d50a3a\MyLibrary.dll       FAST IO DISALLOWED      
19:16:16.0301919        terminal64.exe  29504   IRP_MJ_CREATE   C:\Windows\Microsoft.Net\assembly\GAC_MSIL\MyLibrary\v4.0_8.0.0.0__b03f5f7f11d50a3a\MyLibrary.dll       PATH NOT FOUND  Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
19:16:16.0302483        terminal64.exe  29504   FASTIO_NETWORK_QUERY_OPEN       C:\Windows\Microsoft.Net\assembly\GAC\MyLibrary\v4.0_8.0.0.0__b03f5f7f11d50a3a\MyLibrary.dll    FAST IO DISALLOWED      
19:16:16.0302813        terminal64.exe  29504   IRP_MJ_CREATE   C:\Windows\Microsoft.Net\assembly\GAC\MyLibrary\v4.0_8.0.0.0__b03f5f7f11d50a3a\MyLibrary.dll    PATH NOT FOUND  Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
19:16:16.0303375        terminal64.exe  29504   FASTIO_NETWORK_QUERY_OPEN       C:\Windows\assembly\GAC_64\MyLibrary\8.0.0.0__b03f5f7f11d50a3a\MyLibrary.dll    FAST IO DISALLOWED      
19:16:16.0303706        terminal64.exe  29504   IRP_MJ_CREATE   C:\Windows\assembly\GAC_64\MyLibrary\8.0.0.0__b03f5f7f11d50a3a\MyLibrary.dll    PATH NOT FOUND  Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
19:16:16.0304259        terminal64.exe  29504   FASTIO_NETWORK_QUERY_OPEN       C:\Windows\assembly\GAC_MSIL\MyLibrary\8.0.0.0__b03f5f7f11d50a3a\MyLibrary.dll  FAST IO DISALLOWED      
19:16:16.0304603        terminal64.exe  29504   IRP_MJ_CREATE   C:\Windows\assembly\GAC_MSIL\MyLibrary\8.0.0.0__b03f5f7f11d50a3a\MyLibrary.dll  PATH NOT FOUND  Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
19:16:16.0305151        terminal64.exe  29504   FASTIO_NETWORK_QUERY_OPEN       C:\Windows\assembly\GAC\MyLibrary\8.0.0.0__b03f5f7f11d50a3a\MyLibrary.dll       FAST IO DISALLOWED      
19:16:16.0305481        terminal64.exe  29504   IRP_MJ_CREATE   C:\Windows\assembly\GAC\MyLibrary\8.0.0.0__b03f5f7f11d50a3a\MyLibrary.dll       PATH NOT FOUND  Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
19:16:16.0307378        terminal64.exe  29504   FASTIO_NETWORK_QUERY_OPEN       C:\Users\myuser\Documents\MetaTrader 5\MyLibrary.dll    FAST IO DISALLOWED      
19:16:16.0307742        terminal64.exe  29504   IRP_MJ_CREATE   C:\Users\myuser\Documents\MetaTrader 5\MyLibrary.dll    NAME NOT FOUND  Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
19:16:16.0308260        terminal64.exe  29504   FASTIO_NETWORK_QUERY_OPEN       C:\Users\myuser\Documents\MetaTrader 5\MyLibrary\MyLibrary.dll  FAST IO DISALLOWED      
19:16:16.0308535        terminal64.exe  29504   IRP_MJ_CREATE   C:\Users\myuser\Documents\MetaTrader 5\MyLibrary\MyLibrary.dll  PATH NOT FOUND  Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
19:16:16.0309112        terminal64.exe  29504   FASTIO_NETWORK_QUERY_OPEN       C:\Users\myuser\Documents\MetaTrader 5\MyLibrary.exe    FAST IO DISALLOWED      
19:16:16.0309481        terminal64.exe  29504   IRP_MJ_CREATE   C:\Users\myuser\Documents\MetaTrader 5\MyLibrary.exe    NAME NOT FOUND  Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
19:16:16.0309974        terminal64.exe  29504   FASTIO_NETWORK_QUERY_OPEN       C:\Users\myuser\Documents\MetaTrader 5\MyLibrary\MyLibrary.exe  FAST IO DISALLOWED      
19:16:16.0310248        terminal64.exe  29504   IRP_MJ_CREATE   C:\Users\myuser\Documents\MetaTrader 5\MyLibrary\MyLibrary.exe  PATH NOT FOUND  Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
 
ama bamo #: To be honest I cannot find much information about DLL resolving order, caveats tricks etc. 

In truth, DLL programming is beyond the scope of this forum, because DLL programming belongs in the realm of general Windows programming, not MQL5/MetaTrader. It is an advanced programming skill requirement.

The only part that is within scope, is how MQL5 declares the use of DLLs, and calls the exported functions from those DLLs (and how parameters are passed).

The rest is then needs to be addressed by knowledge and skills obtained from other sources.

 
Fernando Carreiro #:

In truth, DLL programming is beyond the scope of this forum, because DLL programming belongs in the realm of general Windows programming, not MQL5/MetaTrader. It is an advanced programming skill requirement.

The only part that is within scope, is how MQL5 declares the use of DLLs, and calls the exported functions from those DLLs (and how parameters are passed).

The rest is then needs to be addressed by knowledge and skills obtained from other sources.

Understood.

 
Fernando Carreiro #:

In truth, DLL programming is beyond the scope of this forum, because DLL programming belongs in the realm of general Windows programming, not MQL5/MetaTrader. It is an advanced programming skill requirement.

The only part that is within scope, is how MQL5 declares the use of DLLs, and calls the exported functions from those DLLs (and how parameters are passed).

The rest is then needs to be addressed by knowledge and skills obtained from other sources.

There's more on the topic in docs here: