Service 'Abnormal termination' graceful exit handling

 

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


 

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
  • 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...