views:

65

answers:

2

I doubt this is even possible. So your app is running and user decides to End Process via Task Manager. Is there a method/action to save data during process.kill? I doubt there is but I had to ask.

Also, if a user shuts down/restarts PC (as in windows update/manual restart), what action would the app execute? Window_Unloaded? On this second question, I would like to find a way to ensure my app does not show up as a 'if you want to restart, kill this app' situation and want to save needed data.

Your two cents is greatly appreciated!

+2  A: 

It's not possible unless you have 2 processes, one detecting other's kill and do some stuff.

The second process may be a Windows Service Application without GUI.

When normal Shutdown event calls, Windows sends quit message to all opened applications and you may do something (if your application do a heavy task then it prevents Windows to Shutdown and Windows automatically asks user if he wants to kill the Application), but in case of Force Shutdown, you can't do anything like saving data or so.

So I suggest you to make your application to save everything needed as soon as possible to prevent these problems.

x86shadow
+1  A: 

If something terminates your running app, then you don't get an opportunity to do anything, just die. You modify your app such that all data is always saved to some persistent location, so if the app dies, the persisted data remains. Obviously you have to design for this. Then if the user does a "save", you commit to the "real" datastore.

If Windows is going to reboot, it should send a message to your app, which you can handle. Not sure if this works for all GUI/console/service -type apps however.

Chris O