Browse Source

Move this to its own file (it's still a nested class though)

Brandon Thetford 1 year ago
parent
commit
e3f5b8f83c
2 changed files with 51 additions and 47 deletions
  1. 51 0
      Terminal.Gui/Application.MainLoopSyncContext.cs
  2. 0 47
      Terminal.Gui/Application.cs

+ 51 - 0
Terminal.Gui/Application.MainLoopSyncContext.cs

@@ -0,0 +1,51 @@
+namespace Terminal.Gui;
+
+public static partial class Application
+{
+    /// <summary>
+    ///     provides the sync context set while executing code in Terminal.Gui, to let
+    ///     users use async/await on their code
+    /// </summary>
+    private sealed class MainLoopSyncContext : SynchronizationContext
+    {
+        public override SynchronizationContext CreateCopy () { return new MainLoopSyncContext (); }
+
+        public override void Post (SendOrPostCallback d, object state)
+        {
+            MainLoop.AddIdle (
+                              () =>
+                              {
+                                  d (state);
+
+                                  return false;
+                              }
+                             );
+        }
+
+        //_mainLoop.Driver.Wakeup ();
+        public override void Send (SendOrPostCallback d, object state)
+        {
+            if (Thread.CurrentThread.ManagedThreadId == _mainThreadId)
+            {
+                d (state);
+            }
+            else
+            {
+                var wasExecuted = false;
+
+                Invoke (
+                        () =>
+                        {
+                            d (state);
+                            wasExecuted = true;
+                        }
+                       );
+
+                while (!wasExecuted)
+                {
+                    Thread.Sleep (15);
+                }
+            }
+        }
+    }
+}

+ 0 - 47
Terminal.Gui/Application.cs

@@ -716,53 +716,6 @@ public static partial class Application
     /// </summary>
     public static bool EndAfterFirstIteration { get; set; }
 
-    //
-    // provides the sync context set while executing code in Terminal.Gui, to let
-    // users use async/await on their code
-    //
-    private sealed class MainLoopSyncContext : SynchronizationContext
-    {
-        public override SynchronizationContext CreateCopy () { return new MainLoopSyncContext (); }
-
-        public override void Post (SendOrPostCallback d, object state)
-        {
-            MainLoop.AddIdle (
-                              () =>
-                              {
-                                  d (state);
-
-                                  return false;
-                              }
-                             );
-        }
-
-        //_mainLoop.Driver.Wakeup ();
-        public override void Send (SendOrPostCallback d, object state)
-        {
-            if (Thread.CurrentThread.ManagedThreadId == _mainThreadId)
-            {
-                d (state);
-            }
-            else
-            {
-                var wasExecuted = false;
-
-                Invoke (
-                        () =>
-                        {
-                            d (state);
-                            wasExecuted = true;
-                        }
-                       );
-
-                while (!wasExecuted)
-                {
-                    Thread.Sleep (15);
-                }
-            }
-        }
-    }
-
     /// <summary>Building block API: Runs the main loop for the created <see cref="Toplevel"/>.</summary>
     /// <param name="state">The state returned by the <see cref="Begin(Toplevel)"/> method.</param>
     public static void RunLoop (RunState state)