Browse Source

WpfSynchronizeInvoke.Invoke: pass exceptions to the calling thread

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5938 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Daniel Grunwald 15 years ago
parent
commit
392585c818
  1. 22
      src/Main/Base/Project/Src/Util/WpfSynchronizeInvoke.cs

22
src/Main/Base/Project/Src/Util/WpfSynchronizeInvoke.cs

@ -7,6 +7,7 @@
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using System.Reflection;
using System.Threading; using System.Threading;
using System.Windows.Threading; using System.Windows.Threading;
@ -103,12 +104,21 @@ namespace ICSharpCode.SharpDevelop
public object Invoke(Delegate method, object[] args) public object Invoke(Delegate method, object[] args)
{ {
if (args.Length == 0) object result = null;
return dispatcher.Invoke(DispatcherPriority.Normal, method); Exception exception = null;
else if (args.Length == 1) dispatcher.Invoke(
return dispatcher.Invoke(DispatcherPriority.Normal, method, args[0]); DispatcherPriority.Normal,
else (Action)delegate {
return dispatcher.Invoke(DispatcherPriority.Normal, method, args[0], args.Splice(1)); try {
result = method.DynamicInvoke(args);
} catch (TargetInvocationException ex) {
exception = ex.InnerException;
}
});
// if an exception occurred, re-throw it on the calling thread
if (exception != null)
throw new TargetInvocationException(exception);
return result;
} }
} }
} }

Loading…
Cancel
Save