in reply to Window Close / Process Termination Handler on Windows
Since the problem occurs when closing the console window by the "x", make it impossible for the user to do that!
I am going partly from memory on this one, but if you start a Tk gui as a detached process (no console window), it is easy to intercept hitting the "x" on the gui window. There are a couple of ways: see Re: Catching WINDOW close event and take actions and from my memory any code right after Mainloop; executes after the "x" is clicked.
I had one GUI app where I implemented some code after Mainloop; to make sure all of the files were saved if the user clicked "x" instead of using the gui to "save and exit" - it is possible to restart the Mainloop. You don't need any fancy buttons...a simple text display widget would be enough. It is possible to have a routine run right after the Mainloop starts (no user "click" required), but I don't remember the exact way to do that.
On a different tack, why are the user's hitting the console "x" button in the first place?
In my experience that is because they think that the program is hung and because of that, closing the window won't matter.
See if you can just print a "dot", "." every so many work units. Do not have a separate timing routine that prints a dot every 3 seconds or whatever. The users will figure out that that is BS. Make each dot represent some unit of actual work performed. This typically will lead to a jerky timing of dots and the users trust that more than some kind of regularly timed dots. Maximum user patience is somewhat south of 90 seconds.
It is also possible that your program shouldn't even have a constantly displayed UI! In Unix lingo this is a daemon, in Windows lingo this is service. If your command line program is just a monitor for this continuously running process, closing it would have no effect upon the underlying process.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Window Close / Process Termination Handler on Windows
by rminner (Chaplain) on Aug 29, 2018 at 21:28 UTC | |
by Marshall (Canon) on Aug 30, 2018 at 00:31 UTC |