title: Autorestart crashed WPF application
body: <p>I need to automatically restart my WPF when it crashes. I tried a few things now but my app still crashes and doesn't catch the error.
  The second problem is I don't know why it crashes. Well I don't know the exception, VS doesn't tell me. Just vshost32.exe has stopped working. All I know is it happens if I load a lot of different files in a small amount of time in a MediaElement. (Maybe Overflow exception or something)</p>
  
  <p>This is my code. It's in the App.xaml and the with "StartupUri" in the XAML removed.</p>
  
  <pre><code>    private void Application_Startup(object sender, StartupEventArgs e)
      {
          AppDomain currentDomain = AppDomain.CurrentDomain;
          currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);
  
          try
          {
              MainWindow m = new MainWindow();
              m.Show();
          }
          catch (Exception)
          {
              MessageBox.Show("test");
          }
      }
  
      static void MyHandler(object sender, UnhandledExceptionEventArgs args)
      {
          Exception e = (Exception)args.ExceptionObject;
          MessageBox.Show("MyHandler caught : " + e.Message);
      }
  
      private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
      {
          MessageBox.Show("test");
      }
  </code></pre>
  
  <p>EDIT//
  Found the exception in the errorlog of windows:
  roughly translated it's this:</p>
  
  <p>Anwendung: newKnoblauch.exe Frameworkversion: v4.0.30319 Description: The process has stopped because of a unhandled exception. Exceptioninfo: Exceptioncode c0000005, Exceptionadresse 55542ECC</p>
  
  <p>Name der fehlerhaften Anwendung: newKnoblauch.exe, Version: 1.0.0.0, Time: 0x4d62e0a6
  Name des fehlerhaften Moduls: wmp.dll, Version: 12.0.7600.16667, Time: 0x4c7dd593
  Exceptioncode: 0xc0000005
  Erroroffset: 0x00182ecc
  ID des fehlerhaften Prozesses: 0xa98</p>