Capture console exit C#

前端 未结 10 1892
悲&欢浪女
悲&欢浪女 2020-11-22 04:01

I have a console application that contains quite a lot of threads. There are threads that monitor certain conditions and terminate the program if they are true. This termi

10条回答
  •  醉话见心
    2020-11-22 05:02

    There is for WinForms apps;

    Application.ApplicationExit += CleanupBeforeExit;
    

    For Console apps, try

    AppDomain.CurrentDomain.DomainUnload += CleanupBeforeExit;
    

    But I am not sure at what point that gets called or if it will work from within the current domain. I suspect not.

提交回复
热议问题