Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

execute final code on exit

Posted on 2009-05-09
7
Medium Priority
?
246 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 1000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 1000 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

705 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