467,911 Members | 1,395 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,911 developers. It's quick & easy.

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

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.

Nov 17 '05 #1
  • viewed: 1653
Share:
4 Replies
My advice u to implement IDisposable interface. On dispose method cleanup
any resource that u like to give back...

--

Thanks,
Yunus Emre ALPÖZEN
BSc, MCAD.NET

<an********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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.

Nov 17 '05 #2
Hi,

Use Application.ApplicationExit event

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

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
<an********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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.

Nov 17 '05 #3
Of course the fundemental problem is someone has to *call* your Dispose method because the runtime certainly won't. Where are you going to put the call to Dispose?

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

My advice u to implement IDisposable interface. On dispose method cleanup
any resource that u like to give back...
Nov 17 '05 #4
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?

--

Thanks,
Yunus Emre ALPÖZEN
BSc, MCAD.NET

"Richard Blewett [DevelopMentor]" <ri******@NOSPAMdevelop.com> wrote in
message news:O7**************@TK2MSFTNGP15.phx.gbl...
Of course the fundemental problem is someone has to *call* your Dispose
method because the runtime certainly won't. Where are you going to put the
call to Dispose?

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

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

Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Creative Acceleration | last post: by
reply views Thread by John . | last post: by
reply views Thread by Ed J | last post: by
2 posts views Thread by Patrick Blackman | last post: by
reply views Thread by Christopher | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.