How to run clean-up-code when Application shuts down.

  • Thread starter Thread starter andersboth
  • Start date Start date
A

andersboth

I want to run some code when my Windows Form Application is being shut
down.

I want to run this code when the Application is being shut down in the
following situation:

1. The App is being shut down by the user.
2. The App is being shut down because of Windows System Shut Down.

3. The App Process is being killed in Task Manager
4. The App is shut down because I click "Stop" in Visual Studio.
5. The App is shut down, because of some reason I forget in this list.

3,4 and 5, ofcause only if possible.

How do I Achive this, in what event should I put my code ??

Best Regards , Anders Both - Denmark.
 
My advice u to implement IDisposable interface. On dispose method cleanup
any resource that u like to give back...
 
Hi,

Use Application.ApplicationExit event

I'm not sure if it does work in 3 though. but you can try it anyway.

cheers,
 
For the class that must be disposed. I implement IDisposable interface and
create an instance of that class with using keyword. It always calls dispose
method after leaving the scope..

Am I right?
 
Back
Top