From 6f8e95412975963424445b8da1021cc2aaa609d1 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 27 Feb 2009 23:10:52 +0000 Subject: [PATCH] Add DispatcherErrorHandler allow WPF addins to use SharpDevelop's unhandled exception dialog. Fixed expected output in failing NRefactory unit test. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3824 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Test/Output/SpecialOutputVisitorTest.cs | 2 +- .../DispatcherErrorHandler.cs | 40 +++++++++++++++++++ .../ICSharpCode.Core.Presentation.csproj | 1 + 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/Main/ICSharpCode.Core.Presentation/DispatcherErrorHandler.cs diff --git a/src/Libraries/NRefactory/Test/Output/SpecialOutputVisitorTest.cs b/src/Libraries/NRefactory/Test/Output/SpecialOutputVisitorTest.cs index 627cd7f2ae..c033da6aa8 100644 --- a/src/Libraries/NRefactory/Test/Output/SpecialOutputVisitorTest.cs +++ b/src/Libraries/NRefactory/Test/Output/SpecialOutputVisitorTest.cs @@ -209,7 +209,7 @@ End Class"); { TestProgramCS2VB("class A { [PreserveSig] public void B(// comment\nint c) {} }", "Class A\n" + - " ' comment\n" + + " ' comment\n" + " _\n" + " Public Sub B(c As Integer)\n" + " End Sub\n" + diff --git a/src/Main/ICSharpCode.Core.Presentation/DispatcherErrorHandler.cs b/src/Main/ICSharpCode.Core.Presentation/DispatcherErrorHandler.cs new file mode 100644 index 0000000000..c492e3820c --- /dev/null +++ b/src/Main/ICSharpCode.Core.Presentation/DispatcherErrorHandler.cs @@ -0,0 +1,40 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Windows.Threading; + +namespace ICSharpCode.Core.Presentation +{ + public static class DispatcherErrorHandler + { + [ThreadStatic] static bool isRegistered; + + /// + /// Registers the WPF error handler for this thread. + /// If the error handler is already registered, this method does nothing. + /// + /// WPF applications should call this method when they initialize to prevent + /// SharpDevelop from crashing completely when there is an error in WPF event handlers. + /// + public static void Register() + { + if (!isRegistered) { + isRegistered = true; + Dispatcher.CurrentDispatcher.UnhandledException += DispatcherUnhandledException; + } + } + + static void DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) + { + if (!e.Handled) { + e.Handled = true; + MessageService.ShowError(e.Exception, "Unhandled WPF exception"); + } + } + } +} diff --git a/src/Main/ICSharpCode.Core.Presentation/ICSharpCode.Core.Presentation.csproj b/src/Main/ICSharpCode.Core.Presentation/ICSharpCode.Core.Presentation.csproj index facbf43dbf..812c2f999e 100644 --- a/src/Main/ICSharpCode.Core.Presentation/ICSharpCode.Core.Presentation.csproj +++ b/src/Main/ICSharpCode.Core.Presentation/ICSharpCode.Core.Presentation.csproj @@ -62,6 +62,7 @@ Properties\GlobalAssemblyInfo.cs +