Browse Source

Move assertion outside the lock.

BDisp 1 year ago
parent
commit
c5aeac060f
1 changed files with 9 additions and 5 deletions
  1. 9 5
      Terminal.Gui/Application.cs

+ 9 - 5
Terminal.Gui/Application.cs

@@ -417,15 +417,19 @@ public static partial class Application
             toplevel.EndInit ();
         }
 
+#if DEBUG_IDISPOSABLE
+        if (Top is { } && toplevel != Top && !_topLevels.Contains (Top))
+        {
+            // This assertion confirm if the Top was already disposed
+            Debug.Assert (Top.WasDisposed);
+            Debug.Assert (Top == _latestClosedRunStateToplevel);
+        }
+#endif
+
         lock (_topLevels)
         {
             if (Top is { } && toplevel != Top && !_topLevels.Contains (Top))
             {
-#if DEBUG_IDISPOSABLE
-                // This assertion confirm if the Top was already disposed
-                Debug.Assert (Top.WasDisposed);
-                Debug.Assert (Top == _latestClosedRunStateToplevel);
-#endif
                 // If Top was already disposed and isn't on the Toplevels Stack,
                 // clean it up here if is the same as _latestClosedRunStateToplevel
                 if (Top == _latestClosedRunStateToplevel)