Added stopwatch

This commit is contained in:
Tig
2024-08-29 18:42:55 -06:00
parent 50e02cc868
commit 4f683d33b1
2 changed files with 38 additions and 2 deletions

View File

@@ -198,10 +198,16 @@ public static partial class Application // Initialization (Init/Shutdown)
public static void Shutdown ()
{
// TODO: Throw an exception if Init hasn't been called.
bool wasInitialized = IsInitialized;
ResetState ();
PrintJsonErrors ();
bool init = IsInitialized;
InitializedChanged?.Invoke (null, new (in init));
if (wasInitialized)
{
bool init = IsInitialized;
InitializedChanged?.Invoke (null, new (in init));
}
}
/// <summary>

View File

@@ -13,6 +13,7 @@ using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json.Serialization;
using Terminal.Gui;
using UICatalog.Scenarios;
using static Terminal.Gui.ConfigurationManager;
using Command = Terminal.Gui.Command;
using RuntimeEnvironment = Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment;
@@ -337,6 +338,14 @@ public class UICatalogApp
Apply ();
scenario.Theme = _cachedTheme;
scenario.TopLevelColorScheme = _topLevelColorScheme;
#if DEBUG_IDISPOSABLE
// Measure how long it takes for the app to shut down
var sw = new Stopwatch ();
string scenarioName = scenario.GetName ();
Application.InitializedChanged += ApplicationOnInitializedChanged;
#endif
scenario.Main ();
scenario.Dispose ();
@@ -345,10 +354,31 @@ public class UICatalogApp
// TODO: Throw if shutdown was not called already
Application.Shutdown ();
VerifyObjectsWereDisposed ();
#if DEBUG_IDISPOSABLE
Application.InitializedChanged -= ApplicationOnInitializedChanged;
void ApplicationOnInitializedChanged (object? sender, EventArgs<bool> e)
{
if (e.CurrentValue)
{
sw.Start ();
}
else
{
sw.Stop ();
Debug.WriteLine ($"Shutdown of {scenarioName} Scenario took {sw.ElapsedMilliseconds}ms");
}
}
#endif
}
StopConfigFileWatcher ();
VerifyObjectsWereDisposed ();
return;
}
private static void VerifyObjectsWereDisposed ()