From 179994014e3a5c6a945325d9b58528d336535f5e Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Thu, 7 Aug 2008 15:16:10 +0000 Subject: [PATCH] Catch unhandled WPF exceptions earlier to prevent exceptions in WPF code from crashing the SharpDevelop process. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3308 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Src/SharpDevelopElementHost.cs | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/SharpDevelopElementHost.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/SharpDevelopElementHost.cs index 768c36d569..701c071822 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/SharpDevelopElementHost.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/SharpDevelopElementHost.cs @@ -7,8 +7,9 @@ using System; using System.Windows; -using System.Windows.Input; using System.Windows.Forms.Integration; +using System.Windows.Input; +using System.Windows.Threading; using ICSharpCode.SharpDevelop.Gui; namespace ICSharpCode.WpfDesign.AddIn @@ -18,6 +19,23 @@ namespace ICSharpCode.WpfDesign.AddIn /// public class SharpDevelopElementHost : ElementHost, IUndoHandler, IClipboardHandler { + [ThreadStatic] + static bool registeredErrorHandler; + + public SharpDevelopElementHost() + { + if (!registeredErrorHandler) { + registeredErrorHandler = true; + Dispatcher.CurrentDispatcher.UnhandledException += CurrentDispatcher_UnhandledException; + } + } + + static void CurrentDispatcher_UnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) + { + ICSharpCode.Core.MessageService.ShowError(e.Exception, "Unhandled WPF exception"); + e.Handled = true; + } + static bool IsEnabled(ICommand command) { return command.CanExecute(null);