I only had abnormal terminations with infinite loops, and being services that you are talking about I guess you are using one, try this instead:
//while (true) while (!IsStopped()) { //... }
I totally agree with the above post, and would like to suggest you also return a result code which you can view in the logs, so that you will know about a certain state of the service when it terminates.
int OnStart(void) { int nResultCode = RESULT_CODE_NORMAL; while( !IsStopped() ) { // Some special condition changes state of service nResultCode = RESULT_CODE_STATE_A; // ... }; // Result code for log entry "service service_name stopped (result code N)" return nResultCode; };
![Service 'Abnormal termination' graceful exit handling Service 'Abnormal termination' graceful exit handling](https://c.mql5.com/36/49/service-abnormal-termination-graceful.jpg)
Service 'Abnormal termination' graceful exit handling
- 2021.08.05
- www.mql5.com
MQL5 Team I have been exploring the Services in MT5 platform and I found that there is no graceful way to stop a service and stopping it causes 'Ab...
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
MQL5 Team
I have been exploring the Services in MT5 platform and I found that there is no graceful way to stop a service and stopping it causes 'Abnormal termination' error.
Can you please add OnDeinit(reason) to Services so that we can do cleanups and exit the loop of OnStart() gracefully please?
Thanks