Просмотр исходного кода

Fixes #4196. Application.Begin doesn't refresh the screen at start (#4197)

* Fixes #4196. Application.Begin doesn't refresh the screen at start

* Reformatting to run CI again

* Revert "Reformatting to run CI again"

This reverts commit ef639c1e6489022a3df840147f2261239f9c2a5d.

* Trying fix an issue where sometimes subview variable is null running unit tests

* Add comment and decrease the delay time
BDisp 1 месяц назад
Родитель
Сommit
3b13d5a83c

+ 10 - 2
Terminal.Gui/App/Application.Run.cs

@@ -212,8 +212,16 @@ public static partial class Application // Run (Begin, Run, End, Stop)
 
         NotifyNewRunState?.Invoke (toplevel, new (rs));
 
-        // Force an Idle event so that an Iteration (and Refresh) happen.
-        Invoke (() => { });
+        if (!ConsoleDriver.RunningUnitTests)
+        {
+            // Force an Idle event to be added to timeout outside the Application.MainThreadId,
+            // so that an Iteration (and Refresh) happen in the Application.MainThreadId
+            Task.Run (() =>
+                      {
+                          Invoke (() => { });
+                          Task.Delay (1).Wait ();
+                      });
+        }
 
         return rs;
     }

+ 1 - 1
Terminal.Gui/ViewBase/View.Drawing.cs

@@ -807,7 +807,7 @@ public partial class View // Drawing APIs
         }
 
         // There was multiple enumeration error here, so calling ToArray - probably a stop gap
-        foreach (View subview in SubViews.ToArray ())
+        foreach (View subview in InternalSubViews)
         {
             if (subview.Frame.IntersectsWith (viewPortRelativeRegion))
             {

+ 2 - 0
Tests/UnitTests/Views/SpinnerViewTests.cs

@@ -11,6 +11,8 @@ public class SpinnerViewTests (ITestOutputHelper output)
     [InlineData (false)]
     public void TestSpinnerView_AutoSpin (bool callStop)
     {
+        ConsoleDriver.RunningUnitTests = true;
+
         SpinnerView view = GetSpinnerView ();
 
         Assert.Empty (Application.MainLoop.TimedEvents.Timeouts);