Solved

execute final code on exit

Posted on 2009-05-09
7
243 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

734 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