title: Generic way to exit a .NET application
body: <p>I understand that there are a few ways to exit an application, such as Application.Exit(), Application.ExitThread(), Environment.Exit(), etc.</p>
  
  <p>I have an external "commons" library, and I'm trying to create a generic FailIf method that logs the failure to the logs, does this and that and this and that, then finally exits the application... here's a short version of it.</p>
  
  <pre><code>    public static void FailIf(Boolean fail, String message, Int32 exitCode = 1)
      {
          if (String.IsNullOrEmpty(message))
              throw new ArgumentNullException("message");
  
          if (fail)
          {
              //Do whatever I need to do
  
              //Currently Environment.Exit(exitCode)
              Environment.Exit(exitCode);
          }
      }
  </code></pre>
  
  <p>I have read that using Environment.Exit isn't the best way to handle things when it comes to WinForm apps, and also when working with WPF apps and Silverlight there are different ways to exit... My question is really:</p>
  
  <p>What do I put to exit gracefully to cover all application types?</p>