title: Does Application.ApplicationExit event work to be notified of exit in non-Winforms apps?
body: <p>Our code library needs to be notified when the application is exiting.  So we have subscribed to the System.Window.Forms.Application.ApplicationExit event.  This works nicely for Winforms apps, but does it also work for other types of applications such as console apps, services, and web apps (such as ASP.NET)? The namespace would suggest that it doesn't, and it presumably gets raised when <code>Application.Exit()</code> is called (explicitly or implictly), which may not be correct to call for these other cases.</p>
  
  <p>Is there some other event which would be better in these other cases or which would be more universal (great if it works for Winforms, too)?  For example, is there an event for when <code>Environment.Exit()</code> is called (console app)?</p>
  
  <p>I found a mention of an Exited event in System.Diagnostic.Process, but this appears to be for monitoring the exit of <em>another</em> process, and it does not appear to be received by a process about itself (for example, <code>Process.GetCurrentProcess().Exited += Process_Exited; Process.GetCurrentProcess().EnableRaisingEvents = true;</code>).  I would think it might only be raised after the process has actually exited, so that wouldn't work.</p>
  
  <p>This is particularly for .NET 2.0 and C#.</p>