Method call when closing the console

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

+6
source share
3 answers

In most cases, you don’t need a special technique ... just add the routine you were thinking about to the end of the program; it’s good that you can write your program this way. However, if you still need to process it, there is a Ctrl + C mechanism or the CancekKeyPress event raised.

Mark this

+1
source

Not! this is not possible because you are not writing code for the console window and you do not have any events to override

0
source

To do this, use assembly language programming.

To use the assembly language construct, use _asm {} in C # // google it next

To stop closing the console window, close the interrupt that is called on ctrl + c, or there is another interrupt that is called when you exit the program. Override it.

-2
source

Source: https://habr.com/ru/post/917965/


All Articles