Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

calling a method when closing console

Tags:

c#

console

Is there a way to force C# compiler, visual studio 2010, to call a method whenever the user closes the console ? I know that this can be done in windows forms by some sort of event handling or using dispose methods, but what about console, is there any similar way to be able to call a method when closing it ?

like image 863
Emo Avatar asked Jun 13 '12 12:06

Emo


1 Answers

You don't need a special technique in most cases...just add the routine you were thinking to the end of the program; well you can write your program in such a manner. However, if you still need to handle it there is a Ctrl+C mechanism or what is called CancekKeyPress event triggered.

Check this

like image 166
deostroll Avatar answered Oct 26 '22 11:10

deostroll