Handling Debug Stop and EA Stop Events

To add comments, please log in or register
Christian Stern
285
Christian Stern  

Hey all,

my first question is about the debug mode. When i stop the debugging mode, the EA in the Terminal simply terminates and i am not able to handle some cleanup tasks like disconnecting from data base.

My second question is similar to the first one. I wrote a daemon ea ( while loop ) which run in his own tick rhyhtmus, but the while loop runs for ever and i could not find any system variable or function to trigger a close request of the current process. My daemon runs so far and do good work, but he has no clean shutdown and leave open database connections which is not cool.

Is there any way to capture a stop request from the normal and debug mode  ?


Thank you & Best regrads, Chris

Christian Stern
285
Christian Stern  

Hey me,


i found the answer for my second question:


do {

  // sth
  Print("Hello World...");

} while ( IsStopped() == 0 );


but still need a solution for handling the debug stop handling.

Anthony Garot
1817
Anthony Garot  
Christian Stern:

Hey all,

my first question is about the debug mode. When i stop the debugging mode, the EA in the Terminal simply terminates and i am not able to handle some cleanup tasks like disconnecting from data base.

Capture a keystroke (e.g. CTRL-Q) in OnChartEvent() then run ExpertRemove(). This will fire off the OnDeinit(), which is where I do my cleanup.

Christian Stern
285
Christian Stern  
Anthony Garot:

Capture a keystroke (e.g. CTRL-Q) in OnChartEvent() then run ExpertRemove(). This will fire off the OnDeinit(), which is where I do my cleanup.

Yo, thank you very much for this idea :D i have implemented and it work perfectly. The only thing i could'nt manage is to combine both, like pressed STRG and Q.

I have this solved with a boolean serie...press first STRG and then Q

Alain Verleyen
36034
Alain Verleyen  
Christian Stern:

Yo, thank you very much for this idea :D i have implemented and it work perfectly. The only thing i could'nt manage is to combine both, like pressed STRG and Q.

I have this solved with a boolean serie...press first STRG and then Q

See TerminalInfoInteger.

Anthony Garot
1817
Anthony Garot  
Alain Verleyen:

See TerminalInfoInteger.

Yes, as Alain points out, TerminalInfoInteger() will give you a useful keystate.

   if(id==CHARTEVENT_KEYDOWN)
   {
      // q key
      if ( (int) (lparam) == KEY_Q )
      {
         int keystate = TerminalInfoInteger(TERMINAL_KEYSTATE_CONTROL);
         if ( keystate == -127 || keystate == -128 )
         {
            // This is quicker than right-clicking -> Remove
            Print("Removing Expert");
            ExpertRemove();         
         }
      }
        .
        .
        .
   }
To add comments, please log in or register