atexit, exit delegate in c#

烈酒焚心 提交于 2019-12-01 17:27:27

问题


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?


回答1:


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




回答2:


Maybe the answers to this may help you:

  • How do I trap ctrl-c in a C# console app



回答3:


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




回答4:


If you're running a WinForms app you can add a listener to the Application.ApplicationExit event



来源:https://stackoverflow.com/questions/1679876/atexit-exit-delegate-in-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!