From 392585c81840f8851d7a37a4e99b079a5b1a948a Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 12 Jun 2010 14:09:14 +0000 Subject: [PATCH] WpfSynchronizeInvoke.Invoke: pass exceptions to the calling thread git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5938 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Src/Util/WpfSynchronizeInvoke.cs | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Main/Base/Project/Src/Util/WpfSynchronizeInvoke.cs b/src/Main/Base/Project/Src/Util/WpfSynchronizeInvoke.cs index b6860591da..970324f28f 100644 --- a/src/Main/Base/Project/Src/Util/WpfSynchronizeInvoke.cs +++ b/src/Main/Base/Project/Src/Util/WpfSynchronizeInvoke.cs @@ -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 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; } } }