title: Terminate application after unhandled exception
body: <p>I have a problem in a WPF application. I wrote this code:<br /></p>
  
  <pre><code>public partial class App : Application
  {
      public App()
      {
          AppDomain.CurrentDomain.UnhandledException += new 
              UnhandledExceptionEventHandler(MyHandler);
      }
  
      void MyHandler(object sender, UnhandledExceptionEventArgs e)
      {
          Exception exception = e.ExceptionObject as Exception;
          MessageBox.Show(exception.Message, "ERROR",
                          MessageBoxButton.OK, MessageBoxImage.Error);
      }
  
      ...
  }
  </code></pre>
  
  <p>but when a unhandled exception happens, a lot of MessageBox appear to the screen (the exception happens in a timed routine) and after closing one of them, Windows signals that there is an unhandled exception.<br /><br />
  How can I avoid multiple MessageBoxes?<br />
  How can I avoid the message of an unhandled exception?<br />
  How can I terminate the application after the exception?<br />
  As you can easily suppose, I would like to show a message (but only one) with my MessageBox and then terminate the application without any other message.<br /><br/>
  In a <a href="https://stackoverflow.com/questions/2251868/unhandled-exception">previous question</a> related to this argument, <a href="https://stackoverflow.com/users/103385/kyle-rozendo">Kyle Rozendo</a> told me to use DispatcherUnhandledException. Is it necessary or the code I written is sufficient?<br /><br />
  Thank you.</p>