diff --git a/Terminal.Gui/Application.cs b/Terminal.Gui/Application.cs index b6242ee79..cce9ffcc5 100644 --- a/Terminal.Gui/Application.cs +++ b/Terminal.Gui/Application.cs @@ -531,7 +531,7 @@ public static partial class Application //} - // BUGBUG: This call is likley not needed. + // BUGBUG: This call is likely not needed. toplevel.LayoutSubviews (); toplevel.PositionToplevels (); toplevel.FocusFirst (); @@ -555,26 +555,39 @@ public static partial class Application /// Runs the application by calling with the value of /// . /// - /// See for more details. - public static void Run (Func errorHandler = null, ConsoleDriver driver = null) { Run (errorHandler, driver);} + /// + /// + /// must be called when the application is closing (typically after Run> has returned) to + /// ensure resources are cleaned up and terminal settings restored. + /// + /// + /// The caller is responsible for disposing the object returned by this method. + /// + /// The created object. The caller is responsible for disposing this object. + public static Toplevel Run (Func errorHandler = null, ConsoleDriver driver = null) { return Run (errorHandler, driver); } /// /// Runs the application by calling with a new instance of the /// specified -derived class. /// Calling first is not needed as this function will initialize the application. + /// + /// /// /// must be called when the application is closing (typically after Run> has returned) to /// ensure resources are cleaned up and terminal settings restored. /// - /// - /// See for more details. + /// + /// The caller is responsible for disposing the object returned by this method. + /// + /// /// /// /// The to use. If not specified the default driver for the platform will /// be used ( , , or ). Must be /// if has already been called. /// - public static void Run (Func errorHandler = null, ConsoleDriver driver = null) + /// The created T object. The caller is responsible for disposing this object. + public static Toplevel Run (Func errorHandler = null, ConsoleDriver driver = null) where T : Toplevel, new() { var top = new T () as Toplevel; @@ -582,6 +595,8 @@ public static partial class Application EnsureValidInitialization (top, driver); RunApp (top, errorHandler); + + return top; } /// Runs the main loop on the given container. diff --git a/UICatalog/Scenarios/BackgroundWorkerCollection.cs b/UICatalog/Scenarios/BackgroundWorkerCollection.cs index cc4d5b278..4f30630fd 100644 --- a/UICatalog/Scenarios/BackgroundWorkerCollection.cs +++ b/UICatalog/Scenarios/BackgroundWorkerCollection.cs @@ -174,12 +174,7 @@ public class BackgroundWorkerCollection : Scenario private void OverlappedMain_Activate (object sender, ToplevelEventArgs top) { - if (top.Toplevel is null) - { - return; - } - - _workerApp?.WriteLog ($"{top.Toplevel.Data} activate."); + _workerApp?.WriteLog ($"{(top.Toplevel is null ? ((Toplevel)sender).Data : top.Toplevel.Data)} activate."); } private void OverlappedMain_Deactivate (object sender, ToplevelEventArgs top)