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. 40
      src/Main/ICSharpCode.Core.Presentation/DispatcherErrorHandler.cs
  2. 1
      src/Main/ICSharpCode.Core.Presentation/ICSharpCode.Core.Presentation.csproj

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

@ -0,0 +1,40 @@ @@ -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 @@ @@ -62,6 +62,7 @@
<Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="ConditionalSeparator.cs" />
<Compile Include="DispatcherErrorHandler.cs" />
<Compile Include="GetBitmapExtension.cs" />
<Compile Include="IStatusUpdate.cs" />
<Compile Include="LocalizeExtension.cs" />

Loading…
Cancel
Save