Does the Application.ApplicationExit application launch a termination message in applications other than Winforms?

Our code library should be notified when the application exits. So, we signed up for the System.Window.Forms.Application.ApplicationExit event. This works well for Winforms applications, but does it also work for other types of applications such as console applications, services, and web applications (e.g. ASP.NET)? The namespace assumes that this is not the case, and it presumably occurs when Application.Exit()called (explicitly or implicitly), which may be incorrect to call these other cases.

Is there any other event that would be better in these other cases or would be more universal (great if it works for Winforms too)? For example, is there an event when it is called Environment.Exit()(console application)?

I found a mention of the Exited event in System.Diagnostic.Process, but it seems to be intended to control the output of another process and it seems that the process does not perceive it about itself (for example, Process.GetCurrentProcess().Exited += Process_Exited; Process.GetCurrentProcess().EnableRaisingEvents = true;). I think that this can only be called after the process really exited, so this will not work.

This is especially true for .NET 2.0 and C #.

+5
source share
1 answer

- ( cookie , , ).

, :

System.Windows.Forms.Application.ThreadExit - System.Windows.Forms.Application.ApplicationExit - , System.AppDomain.CurrentDomain.DomainUnload - , , System.AppDomain.CurrentDomain.ProcessExit - , System.AppDomain.CurrentDomain.UnhandledException - , , .

DomainUnload ProcessExit , , ( ) (, ). , ( ), , . , , UnhandledException ( .NET2.0 ) , . .NET.

, ProcessExit ( 4 ?), "" . -, .

Application WinForms ( , WPF). , , . ThreadExit System.Threading.Thread, (Application.Run())) , ApplicationExit . , Application.Run() , , , . , WinForms .

- System.Windows.Forms.Application.ThreadException. Windows , , , (, , ) . ( ) ( ). ( ), , . . MSDN System.Windows.Forms.Applicaton.SetUnhandledExceptionMode().

+9

All Articles