Author: jpobst
Date: 2007-09-26 11:12:22 -0400 (Wed, 26 Sep 2007)
New Revision: 86408

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/Control.cs
   
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/WindowsFormsSynchronizationContext.cs
Log:
2007-09-26  Jonathan Pobst  <[EMAIL PROTECTED]>

        * Application.cs: Move the sync context stuff to Run instead of RunLoop
        so that it doesn't get uninstalled on modal forms.
        * Control.cs: Install a sync context when a control is created.
        * WindowsFormsSyncronizationContext.cs: Create a private static control
        to invoke on.  This is easier than trying to find a created control we
        can use.
        [Fixes 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-26 15:11:41 UTC (rev 86407)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Application.cs   
2007-09-26 15:12:22 UTC (rev 86408)
@@ -602,17 +602,30 @@
 
                public static void Run ()
                {
-                       RunLoop (false, new ApplicationContext ());
+                       Run (new ApplicationContext ());
                }
 
                public static void Run (Form mainForm)
                {
-                       RunLoop (false, new ApplicationContext (mainForm));
+                       Run (new ApplicationContext (mainForm));
                }
 
                public static void Run (ApplicationContext context)
                {
+#if NET_2_0
+                       // If a sync context hasn't been created by now, create
+                       // a default one
+                       if (SynchronizationContext.Current == null)
+                               
SynchronizationContext.SetSynchronizationContext (new SynchronizationContext 
());
+#endif
+                               
                        RunLoop (false, context);
+                       
+#if NET_2_0
+                       // Reset the sync context back to the default
+                       if (SynchronizationContext.Current is 
WindowsFormsSynchronizationContext)
+                               WindowsFormsSynchronizationContext.Uninstall ();
+#endif
                }
 
                private static void DisableFormsForModalLoop (Queue toplevels, 
ApplicationContext context)
@@ -703,11 +716,6 @@
                        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;
@@ -857,10 +865,6 @@
 
                        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-26 15:11:41 UTC (rev 86407)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2007-09-26 15:12:22 UTC (rev 86408)
@@ -1,3 +1,13 @@
+2007-09-26  Jonathan Pobst  <[EMAIL PROTECTED]>
+
+       * Application.cs: Move the sync context stuff to Run instead of RunLoop
+       so that it doesn't get uninstalled on modal forms.
+       * Control.cs: Install a sync context when a control is created.
+       * WindowsFormsSyncronizationContext.cs: Create a private static control
+       to invoke on.  This is easier than trying to find a created control we
+       can use.
+       [Fixes bug #327608]
+
 2007-09-25  Jonathan Pobst  <[EMAIL PROTECTED]>
 
        * Application.cs: Install a WindowsFormsSynchronizationContext in the

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs       
2007-09-26 15:11:41 UTC (rev 86407)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs       
2007-09-26 15:12:22 UTC (rev 86408)
@@ -979,6 +979,12 @@
                #region Public Constructors
                public Control ()
                {
+#if NET_2_0
+                       if (WindowsFormsSynchronizationContext.AutoInstall)
+                               if (!(SynchronizationContext.Current is 
WindowsFormsSynchronizationContext))
+                                       
SynchronizationContext.SetSynchronizationContext (new 
WindowsFormsSynchronizationContext ());
+#endif
+
                        layout_type = LayoutType.Anchor;
                        anchor_style = AnchorStyles.Top | AnchorStyles.Left;
 

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-26 15:11:41 UTC (rev 86407)
+++ 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/WindowsFormsSynchronizationContext.cs
    2007-09-26 15:12:22 UTC (rev 86408)
@@ -32,17 +32,18 @@
        public sealed class WindowsFormsSynchronizationContext : 
SynchronizationContext, IDisposable
        {
                private static bool auto_installed;
-               private Control invoke_control;
+               private static Control invoke_control;
                private static SynchronizationContext previous_context;
                
                #region Public Constructor
                public WindowsFormsSynchronizationContext ()
                {
-                       invoke_control = 
Application.MWFThread.Current.Context.MainForm;
                }
                
                static WindowsFormsSynchronizationContext ()
                {
+                       invoke_control = new Control ();
+                       invoke_control.CreateControl ();
                        auto_installed = true;
                        previous_context = SynchronizationContext.Current;
                }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to