title: How do you get an event for every unhandled exception in a mixed WinForms/WPF application
body: <p>I want to get an event for every unhandled excpetion in my application, so I can write it to a log file. The application started as a Windows Forms application, where this can easily be done by subscribing the static <code>System.Windows.Forms.Application.ThreadException</code> event and calling <code>System.Windows.Forms.Application.SetUnhandledExceptionMode</code>. </p>
  
  <p>In a pure WPF application, it's easy too, I just have to subscribe the <code>System.Windows.Application</code> instance's <code>DispatcherUnhandledException</code> event. </p>
  
  <p>But how can I do this for a mixed application (i.e. a Windows Forms application with some WPF dialog windows and controls), where I don't have a global <code>System.Windows.Application</code> instance? <code>System.Windows.Application.Current</code> is <code>null</code> at startup, when I try to subscribe the event. I've tried creating my own instance of <code>System.Windows.Application</code>, but apparently it gets destroyed when the first WPF window is closed. If I try to open another WPF window after that, I get an <code>EngineExecutionException</code>.</p>