1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

ON CLOSE, GOTO, and X-ing the console

Discussion in 'Support' started by vefatica, Jan 15, 2015.

  1. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,959
    Likes Received:
    30
    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 )
     
  2. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,959
    Likes Received:
    30
    I don't have a TCEXIT.
     
  3. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,860
    Likes Received:
    83
    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.
     
  4. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,959
    Likes Received:
    30
    I wanted to do quite a bit ON CLOSE. Fortunately, a multiline command works fine.
    Code:
    on close (
       delay 1
       echo foo
       delay 1
       echo bar
       delay 1)
    do forever ( echo %_do_loop & delay 1 )
    
     
  5. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,860
    Likes Received:
    83
    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.
     
  6. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,959
    Likes Received:
    30
    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.
     

Share This Page