Author: jpobst
Date: 2007-09-25 12:04:22 -0400 (Tue, 25 Sep 2007)
New Revision: 86342
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Application.cs
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/WindowsFormsSynchronizationContext.cs
Log:
2007-09-25 Jonathan Pobst <[EMAIL PROTECTED]>
* Application.cs: Install a WindowsFormsSynchronizationContext in the
run loop, and uninstall it when done.
* WindowsFormsSynchronizationContext.cs: Implement.
[Fixes the common case in bug #327608]
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Application.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Application.cs
2007-09-25 15:57:26 UTC (rev 86341)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Application.cs
2007-09-25 16:04:22 UTC (rev 86342)
@@ -703,6 +703,11 @@
previous_thread_context = thread.Context;
thread.Context = context;
+#if NET_2_0
+ if (!(SynchronizationContext.Current is
WindowsFormsSynchronizationContext))
+
SynchronizationContext.SetSynchronizationContext (new
WindowsFormsSynchronizationContext ());
+#endif
+
if (context.MainForm != null) {
context.MainForm.is_modal = Modal;
context.MainForm.context = context;
@@ -852,6 +857,10 @@
thread.Context = previous_thread_context;
+#if NET_2_0
+ WindowsFormsSynchronizationContext.Uninstall ();
+#endif
+
if (!Modal)
thread.Exit();
}
Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
2007-09-25 15:57:26 UTC (rev 86341)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
2007-09-25 16:04:22 UTC (rev 86342)
@@ -1,3 +1,10 @@
+2007-09-25 Jonathan Pobst <[EMAIL PROTECTED]>
+
+ * Application.cs: Install a WindowsFormsSynchronizationContext in the
+ run loop, and uninstall it when done.
+ * WindowsFormsSynchronizationContext.cs: Implement.
+ [Fixes the common case in bug #327608]
+
2007-09-23 Gert Driesen <[EMAIL PROTECTED]>
* DataGridViewCellCollection.cs: Added argument checks for indexers.
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/WindowsFormsSynchronizationContext.cs
===================================================================
---
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/WindowsFormsSynchronizationContext.cs
2007-09-25 15:57:26 UTC (rev 86341)
+++
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/WindowsFormsSynchronizationContext.cs
2007-09-25 16:04:22 UTC (rev 86342)
@@ -20,14 +20,69 @@
// Copyright (c) 2007 Novell, Inc.
//
-using System;
+using System;
+using System.Threading;
#if NET_2_0
+// Some implementation details:
+// http://msdn.microsoft.com/msdnmag/issues/06/06/NETMatters/default.aspx
namespace System.Windows.Forms
{
- public static class WindowsFormsSynchronizationContext {
+ public sealed class WindowsFormsSynchronizationContext :
SynchronizationContext, IDisposable
+ {
+ private static bool auto_installed;
+ private Control invoke_control;
+ private static SynchronizationContext previous_context;
+
+ #region Public Constructor
+ public WindowsFormsSynchronizationContext ()
+ {
+ invoke_control =
Application.MWFThread.Current.Context.MainForm;
+ }
+
+ static WindowsFormsSynchronizationContext ()
+ {
+ auto_installed = true;
+ previous_context = SynchronizationContext.Current;
+ }
+ #endregion
+
+ #region Public Properties
+ public static bool AutoInstall {
+ get { return auto_installed; }
+ set { auto_installed = value; }
+ }
+ #endregion
+
+ #region Public Methods
+ public override SynchronizationContext CreateCopy ()
+ {
+ return base.CreateCopy ();
+ }
+
+ public void Dispose ()
+ {
+ }
+
+ public override void Post (SendOrPostCallback d, object state)
+ {
+ invoke_control.BeginInvoke (d, new object[] { state });
+ }
+
+ public override void Send (SendOrPostCallback d, object state)
+ {
+ invoke_control.Invoke (d, new object[] { state });
+ }
+
+ public static void Uninstall ()
+ {
+ if (previous_context == null)
+ previous_context = new SynchronizationContext
();
+
+ SynchronizationContext.SetSynchronizationContext
(previous_context);
+ }
+ #endregion
}
}
-
#endif
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches