Browse Source

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
shortcuts
Daniel Grunwald 17 years ago
parent
commit
6f8e954129
  1. 2
      src/Libraries/NRefactory/Test/Output/SpecialOutputVisitorTest.cs
  2. 40
      src/Main/ICSharpCode.Core.Presentation/DispatcherErrorHandler.cs
  3. 1
      src/Main/ICSharpCode.Core.Presentation/ICSharpCode.Core.Presentation.csproj

2
src/Libraries/NRefactory/Test/Output/SpecialOutputVisitorTest.cs

@ -209,7 +209,7 @@ End Class");
{ {
TestProgramCS2VB("class A { [PreserveSig] public void B(// comment\nint c) {} }", TestProgramCS2VB("class A { [PreserveSig] public void B(// comment\nint c) {} }",
"Class A\n" + "Class A\n" +
" ' comment\n" + " ' comment\n" +
" <PreserveSig> _\n" + " <PreserveSig> _\n" +
" Public Sub B(c As Integer)\n" + " Public Sub B(c As Integer)\n" +
" End Sub\n" + " End Sub\n" +

40
src/Main/ICSharpCode.Core.Presentation/DispatcherErrorHandler.cs

@ -0,0 +1,40 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Windows.Threading;
namespace ICSharpCode.Core.Presentation
{
public static class DispatcherErrorHandler
{
[ThreadStatic] static bool isRegistered;
/// <summary>
/// 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.
/// </summary>
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");
}
}
}
}

1
src/Main/ICSharpCode.Core.Presentation/ICSharpCode.Core.Presentation.csproj

@ -62,6 +62,7 @@
<Link>Properties\GlobalAssemblyInfo.cs</Link> <Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile> </Compile>
<Compile Include="ConditionalSeparator.cs" /> <Compile Include="ConditionalSeparator.cs" />
<Compile Include="DispatcherErrorHandler.cs" />
<Compile Include="GetBitmapExtension.cs" /> <Compile Include="GetBitmapExtension.cs" />
<Compile Include="IStatusUpdate.cs" /> <Compile Include="IStatusUpdate.cs" />
<Compile Include="LocalizeExtension.cs" /> <Compile Include="LocalizeExtension.cs" />

Loading…
Cancel
Save