[Mono-bugs] [Bug 81740][Nor] Changed - Bugs in the use of tailcalls and in the System.Threading.SynchronizationContext.Current

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Tue Jun 12 13:27:37 EDT 2007


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by s.guido at email.it.

http://bugzilla.ximian.com/show_bug.cgi?id=81740

--- shadow/81740	2007-06-05 11:21:52.000000000 -0400
+++ shadow/81740.tmp.31422	2007-06-12 13:27:37.000000000 -0400
@@ -205,6 +205,45 @@
 included) to get the exception
 Thanks
 
 ------- Additional Comments From lupus at ximian.com  2007-06-05 11:21 -------
 A smaller test case would be easier to debug (especially one that
 doesn't depend on F#).
+
+------- Additional Comments From s.guido at email.it  2007-06-12 13:27 -------
+Hi, here is the workaround that Don Syme has put in the next relase of F#.
+(in the worker.fs of the CuncurrentLife sample in the F# distribution)
+
+----------------------------------
+// Capture the synchronization context of the thread that creates this
+object. This
+// allows us to send messages back to the GUI thread painlessly.
+let callerCtxt = 
+    match System.Threading.SynchronizationContext.Current with 
+    | null -> null //
+System.ComponentModel.AsyncOperationManager.SynchronizationContext
+    | x -> x
+//do if callerCtxt = null then failwith "Couldn't detect the
+synchronization context of the calling thread"
+    
+let runInCallerCtxt f = 
+    match callerCtxt with 
+    | null -> 
+        // callerCtxt is null on Mono. This is a bug.
+System.Threading.SynchronizationContext.Current doesn't return a useful
+        // result. This is a little unfortunate.
+System.ComponentModel.AsyncOperationManager.SynchronizationContext returns
+        // an inconsistent result.
+        //
+        // So here we works around, where  We find the open form and
+send to it. 
+        if System.Windows.Forms.Application.OpenForms.Count > 0 then 
+           
+System.Windows.Forms.Application.OpenForms.Item(0).BeginInvoke(new
+System.Windows.Forms.MethodInvoker(fun _ -> f())) |> ignore
+    | _ -> callerCtxt.Post((fun _ -> f()),null)
+
+----------------------------------
+
+Sorry, but I don not have the knowledge for reproducing this bug with C#
+(I will try to write a smallest test case soon)
+Thanks and best regards


More information about the mono-bugs mailing list