Solved

execute final code on exit

Posted on 2009-05-09
7
238 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now