Glenn BarnasAdministrator
(KiX Supporter)
2015-11-05 10:46 PM
perform tasks on exit

I have a KF Classic application that displays a simple form. When you click the [close] button or the [X], the application minimizes to the system tray. Clicking the sys-tray icon raises the app to a normal window again. There is no option for the user to exit the application.

The application launches from the Startup folder in the start menu and runs as long as the user is logged in.

Here's my challenge - each day I copy the tokenized script to the user's workstation to insure that the latest version is available. I terminate the running copy (think TaskKill), copy the latest copy, and then invoke it with an arg that forces the application to minimize to the system tray immediately without displaying a window. (When it starts normally, it displays the status window for 10 seconds before minimizing.)

This works fine and the user is unaware if the event, with one exception. When the running (and minimized) app is terminated, it leaves the icon in the system tray. If the system tray is later opened, several "ghost" icons are present and will disappear when moused over.

The code I have for shutdown , which removes the icon and raises/hides the window, does not execute if the task is killed.

Is there some way to trap the Process Terminate request so I can perform an orderly shutdown? Alternatively, is there some way to communicate with the running process?

The app does wake up every 15 seconds to check for pending messages to display to the user, so I could check for some other "thing" to initiate a graceful shutdown, but I really don't want to use flag files and such (which does work as desired). I don't like the flag-file method because it's easy to fool the system if you know it's there, and it can take up to 15 seconds to take effect. I'd prefer some other (non timed) method to communicate a shutdown request.

Thanks!

Glenn