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

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.
 
Y

Yunus Emre ALPÖZEN [MCAD.NET]

My advice u to implement IDisposable interface. On dispose method cleanup
any resource that u like to give back...
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Use Application.ApplicationExit event

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

cheers,
 
Y

Yunus Emre ALPÖZEN [MCAD.NET]

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top