Solved

execute final code on exit

Posted on 2009-05-09
7
242 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 30

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 30

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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

756 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