Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

atexit, exit delegate in c#

Tags:

c#

exit

In c++ there is a function called atexit where you can register functions which should be run when the system exits. Are there any similar events in C#?

UPDATE: The AppDomain.ProcessExit doesn't seem to catch Ctrl-C or Ctrl-Break. Anyone knows anything about that?

like image 628
Mats Fredriksson Avatar asked Nov 05 '09 11:11

Mats Fredriksson


3 Answers

You can check the ProcessExit and DomainUnload events of the AppDomain class.

like image 84
Fredrik Mörk Avatar answered Sep 22 '22 16:09

Fredrik Mörk


Maybe the answers to this may help you:

  • How do I trap ctrl-c in a C# console app
like image 36
Svish Avatar answered Sep 22 '22 16:09

Svish


There's the Application.ApplicationExit event if you've a WinForms application. For WPF there's Application.Exit.

like image 1
andyp Avatar answered Sep 23 '22 16:09

andyp