Browse Source

Prevents run stagingUI if OverlappedTop is null.

BDisp 1 year ago
parent
commit
155e0a4232
1 changed files with 18 additions and 1 deletions
  1. 18 1
      UICatalog/Scenarios/BackgroundWorkerCollection.cs

+ 18 - 1
UICatalog/Scenarios/BackgroundWorkerCollection.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
+using System.Diagnostics;
 using System.Threading;
 using Terminal.Gui;
 
@@ -19,6 +20,10 @@ public class BackgroundWorkerCollection : Scenario
 
         //main.Dispose ();
         Application.Top.Dispose ();
+
+#if DEBUG_IDISPOSABLE
+        Debug.Assert (Application.OverlappedChildren.Count == 0);
+#endif
     }
 
     public override void Run () { }
@@ -357,6 +362,12 @@ public class BackgroundWorkerCollection : Scenario
             Add (_listLog);
 
             Closing += WorkerApp_Closing;
+            Closed += WorkerApp_Closed;
+        }
+
+        private void WorkerApp_Closed (object sender, ToplevelEventArgs e)
+        {
+            CancelWorker ();
         }
         private void WorkerApp_Closing (object sender, ToplevelClosingEventArgs e)
         {
@@ -475,7 +486,13 @@ public class BackgroundWorkerCollection : Scenario
 
                                                  _stagingsUi.Add (stagingUI);
                                                  _stagingWorkers.Remove (staging);
-
+#if DEBUG_IDISPOSABLE
+                                                 if (Application.OverlappedTop is null)
+                                                 {
+                                                     stagingUI.Dispose ();
+                                                     return;
+                                                 }
+#endif
                                                  Application.Run (stagingUI);
                                                  stagingUI.Dispose ();
                                              }