Windows: how to perform cleanup actions when the console window closes
> You need to intercept the various events that may cause a console
> windows to be closed; this is done via the Windows API call
> SetConsoleCtrlHandler .
> https://stackoverflow.com/a/30843219/6944068 gives an overview
very informative, thanks!
> I don't know how to register a Haskell function as a Windows callback,
> that will have to be answered by somebody else.
The documentation for this function says that
> When the event is received, if the
> 'Handler' value is @Catch f@, then a new thread will be spawned by
> the system to execute @f e@, where @e@ is the 'ConsoleEvent' that
> was received.
I wonder if I can add a handler function that detects Control-C and
Close events, and responds by throwing a userInterrupt exception to
the main thread, and then sleeping forever. The main thread then sees
an asynchronous exception, the bracket cleanup action fires (which is
my goal here), main thread shuts down and the program stops. Will try
to experiment with that later.