Solved

execute final code on exit

Posted on 2009-05-09
7
241 Views
Last Modified: 2012-05-06
I'm writing a console based c# application.

I just wanted to know if there is a way to execute some code when the program is being forced to close. (like writing "program exit" in a log file)
0
Comment
Question by:ultramoo
7 Comments
 
LVL 22

Accepted Solution

by:
cookre earned 250 total points
ID: 24346597
0
 
LVL 29

Expert Comment

by:anarki_jimbel
ID: 24351694
0
 

Author Comment

by:ultramoo
ID: 24351733
I don't seem to understand how SetConsoleCtrlHandler Function() will help me.. let alone the examples are in c++. Got somthing in c#?

anarki_jimbel - thanks but thats for a case of forms (windows UI) .. i'm running this in Console mode. (no windows forms or UI)

0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 3

Expert Comment

by:mpf1748
ID: 24355250
The System.AppDomain class contains an event called ProcessExit. You can handle this event under the Current AppDomain (AppDomain.CurrentDomain.ProcessExit). You might look at the documentation for this event because a few caveats do exist.
0
 
LVL 11

Expert Comment

by:Agarici
ID: 24356192
you can try using Application.ApplicationExit event

hth,
A.<!--[if gte mso 9]>   Normal  0  21      false  false  false                     MicrosoftInternetExplorer4 <![endif]--><!--[if gte mso 9]>  <![endif]--><!--[if !mso]><![endif]--><!--[if gte mso 10]><![endif]-->
0
 
LVL 29

Assisted Solution

by:anarki_jimbel
anarki_jimbel earned 250 total points
ID: 24359065
Try this solution - also see comments:

http://geekswithblogs.net/mrnat/archive/2004/09/23/11594.aspx
0
 

Author Closing Comment

by:ultramoo
ID: 31579845
Thanks. After a lot of playing around with this function (had probblems with it when used within a thread etc..) I've finally got it to work.

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question