Hi Guys,
I submitted a bug (https://bugzilla.novell.com/show_bug.cgi?id=497175)
a while ago about Control.Invoke not propagating an exception thrown
in the callee back to the caller. I made a patch which fixes this
issue, and I've been testing it with success for a while now.
I attached the patch to the bug, but it appears to have gotten lost in
the mists o' time... so I've attached it to this e-mail for review -
and hopefully inclusion into the source tree!
Thanks!
--
Tom Spink
Frank Lloyd Wright - "TV is chewing gum for the eyes." -
http://www.brainyquote.com/quotes/authors/f/frank_lloyd_wright.html
Index: class/Managed.Windows.Forms/System.Windows.Forms/XplatUIDriver.cs
===================================================================
--- class/Managed.Windows.Forms/System.Windows.Forms/XplatUIDriver.cs (revision 132351)
+++ class/Managed.Windows.Forms/System.Windows.Forms/XplatUIDriver.cs (working copy)
@@ -476,7 +476,19 @@
{
AsyncMethodData data = (AsyncMethodData) state;
AsyncMethodResult result = data.Result;
- object ret = data.Method.DynamicInvoke (data.Args);
+
+ object ret;
+ try {
+ ret = data.Method.DynamicInvoke (data.Args);
+ } catch (Exception ex) {
+ if (result != null) {
+ result.CompleteWithException (ex);
+ return;
+ }
+
+ throw ex;
+ }
+
if (result != null) {
result.Complete (ret);
}
@@ -513,7 +525,14 @@
try {
AsyncMethodResult result = data.Result;
- object ret = data.Method.DynamicInvoke (data.Args);
+ object ret;
+ try {
+ ret = data.Method.DynamicInvoke (data.Args);
+ } catch (Exception ex) {
+ result.CompleteWithException (ex);
+ return;
+ }
+
result.Complete (ret);
}
finally {
Index: class/Managed.Windows.Forms/System.Windows.Forms/AsyncMethodResult.cs
===================================================================
--- class/Managed.Windows.Forms/System.Windows.Forms/AsyncMethodResult.cs (revision 132351)
+++ class/Managed.Windows.Forms/System.Windows.Forms/AsyncMethodResult.cs (working copy)
@@ -34,6 +34,7 @@
private object state;
private bool completed;
private object return_value;
+ private Exception exception;
public AsyncMethodResult ()
{
@@ -68,10 +69,18 @@
public object EndInvoke ()
{
lock (this) {
- if (completed)
- return return_value;
+ if (completed) {
+ if (exception == null)
+ return return_value;
+ else
+ throw exception;
+ }
}
handle.WaitOne ();
+
+ if (exception != null)
+ throw exception;
+
return return_value;
}
@@ -83,6 +92,15 @@
handle.Set ();
}
}
+
+ public void CompleteWithException (Exception ex)
+ {
+ lock (this) {
+ completed = true;
+ exception = ex;
+ handle.Set ();
+ }
+ }
}
}
_______________________________________________
Mono-winforms-list maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-winforms-list