+ public static void Run (ApplicationContext context)
+ {
+ // If a sync context hasn't been created by now, create
+ // a default one
+ if (SynchronizationContext.Current == null)
+ SynchronizationContext.SetSynchronizationContext (new SynchronizationContext ());
+
+ RunLoop (false, context);
+
+ // Reset the sync context back to the default
+ if (SynchronizationContext.Current is WindowsFormsSynchronizationContext)
+ WindowsFormsSynchronizationContext.Uninstall ();
+ }
+
+ private static void DisableFormsForModalLoop (Queue toplevels, ApplicationContext context)
+ {
+ Form f;
+
+ lock (forms) {
+ IEnumerator control = forms.GetEnumerator ();
+
+ while (control.MoveNext ()) {
+ f = (Form)control.Current;
+
+ // Don't disable the main form.
+ if (f == context.MainForm) {
+ continue;
+ }
+
+ // Don't disable any children of the main form.
+ // These do not have to be MDI children.
+ Control current = f;
+ bool is_child_of_main = false; ;
+
+ do {
+ if (current.Parent == context.MainForm) {
+ is_child_of_main = true;
+ break;
+ }
+ current = current.Parent;
+ } while (current != null);
+
+ if (is_child_of_main)
+ continue;
+
+ // Disable the rest
+ if (f.IsHandleCreated && XplatUI.IsEnabled (f.Handle)) {
+#if DebugRunLoop
+ Console.WriteLine(" Disabling form {0}", f);
+#endif
+ XplatUI.EnableWindow (f.Handle, false);
+ toplevels.Enqueue (f);
+ }
+ }
+ }
+
+ }
+
+
+ private static void EnableFormsForModalLoop (Queue toplevels, ApplicationContext context)
+ {
+ while (toplevels.Count > 0) {
+#if DebugRunLoop
+ Console.WriteLine(" Re-Enabling form form {0}", toplevels.Peek());
+#endif
+ Form c = (Form) toplevels.Dequeue ();
+ if (c.IsHandleCreated) {
+ XplatUI.EnableWindow (c.window.Handle, true);
+ context.MainForm = c;
+ }
+ }
+#if DebugRunLoop
+ Console.WriteLine(" Done with the re-enable");
+#endif
+ }
+
+ internal static void RunLoop (bool Modal, ApplicationContext context)
+ {