ON CLOSE, GOTO, and X-ing the console

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
#1
If this BTM is running and I close the console via the "X", I hear the beep.
Code:
on close beep
do forever ( delay 1 )
If this BTM is running and I close the console via the "X", I do not hear the beep.
Code:
on close goto done
do forever ( delay 1 )
:done
beep
What's up with that? I'd really like to be able to rely on my ON CLOSE mechanism.

If I do this and X the console, I get a full 5 seconds before the batch file stops and the console closes.
Code:
on close do forever ( delay 1 )
do forever ( echo %_do_loop & delay 1 )
But this way I get no time at all.
Code:
on close goto done
do forever ( echo %_do_loop & delay 1 )
:done
do forever ( delay 1 )
 

rconn

Administrator
Staff member
May 14, 2008
10,100
85
#3
There is no "duration protection" for a GOTO in an ON CLOSE -- once you've moved the execution pointer, TCC drops out of the ON handler and returns to the batch parser to execute the next line. And the batch parser then notices that Windows is shutting down the session, so everything exits.

If you want to do something in an ON CLOSE, you have to do it within the ON CLOSE statement.
 
#6
If you're still using a 32-bit version of Windows, you're going to be restricted to less than 2Gb in your ON CLOSE statement. Which should prove adequate in most cases.

And Windows is going to kill you after ~5 seconds anyway, no matter how much you really wanted to do.
It's not time or resource consuming stuff, just several lines. Hee-hee ... 2GB is ALL my memory. And it's plenty. I rarely go below 1GB free, even after weeks/months of uptime.