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 @@ @@ -7,6 +7,7 @@
using System;
using System.ComponentModel;
using System.Reflection;
using System.Threading;
using System.Windows.Threading;
@ -103,12 +104,21 @@ namespace ICSharpCode.SharpDevelop @@ -103,12 +104,21 @@ namespace ICSharpCode.SharpDevelop
public object Invoke(Delegate method, object[] args)
{
if (args.Length == 0)
return dispatcher.Invoke(DispatcherPriority.Normal, method);
else if (args.Length == 1)
return dispatcher.Invoke(DispatcherPriority.Normal, method, args[0]);
else
return dispatcher.Invoke(DispatcherPriority.Normal, method, args[0], args.Splice(1));
object result = null;
Exception exception = null;
dispatcher.Invoke(
DispatcherPriority.Normal,
(Action)delegate {
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