8
votes

My Racket GUI application needs to do a lot of cleanup work when exiting, i.e. when the user presses the X button. These include killing child processes (which isn't automatic on Windows) etc.

Wrapping the .rkt in a shell script which waits and then does the cleanup is a bit too hacky for me. There are many exit handlers in the Racket documentation (exit-handler etc) but none of them seem to work!

1
Just to clarify: Is your Racket program starting external Windows processes? - soegaard
Yes. Anyways, Metaxal is correct. - ithisa

1 Answers

10
votes

You probably want to augment on-close in frame%, for example:

#lang racket/gui

(send
 (new (class frame% (super-new)
        (define/augment (on-close)
          (displayln "Exiting...")))
      [label "Frame"]
      [width 400] [height 200])
 show #t)

which on my machine prints "Exiting..." when I click the closing cross.