public static void Initialize() { AppDomain.CurrentDomain.UnhandledException += (sender, e) => { if (instance == null) { instance = new ErrorDialog(); } instance.ShowDialog(e.ExceptionObject as Exception); }; Application.ThreadException += (sender, e) => { if (instance == null) { instance = new ErrorDialog(); } instance.ShowDialog(e.Exception); }; }