From 577e14586e20285ee6441dfe21ecac6d075a3bc1 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Wed, 28 Feb 2024 23:44:11 -0800 Subject: [PATCH] Fix TestBA to always shutdown properly --- src/test/burn/TestBA/TestBA.cs | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/test/burn/TestBA/TestBA.cs b/src/test/burn/TestBA/TestBA.cs index d5fca9ef5..6a5be750d 100644 --- a/src/test/burn/TestBA/TestBA.cs +++ b/src/test/burn/TestBA/TestBA.cs @@ -128,9 +128,8 @@ protected override void OnStartup(StartupEventArgs args) base.OnStartup(args); - int redetectCount; string redetect = this.ReadPackageAction(null, "RedetectCount"); - if (String.IsNullOrEmpty(redetect) || !Int32.TryParse(redetect, out redetectCount)) + if (String.IsNullOrEmpty(redetect) || !Int32.TryParse(redetect, out var redetectCount)) { redetectCount = 0; } @@ -180,20 +179,15 @@ protected override void OnStartup(StartupEventArgs args) protected override void Run() { - this.dummyWindow = new Form(); - this.windowHandle = this.dummyWindow.Handle; + using (this.dummyWindow = new Form()) + { + this.windowHandle = this.dummyWindow.Handle; - this.Log("Running TestBA application"); - this.wait.Set(); - Application.Run(); - } + this.Log("Running TestBA application"); + this.wait.Set(); - private void ShutdownUiThread() - { - if (this.dummyWindow != null) - { - this.dummyWindow.Invoke(new Action(Application.ExitThread)); - this.dummyWindow.Dispose(); + Application.Run(); + this.dummyWindow = null; } var exitCode = this.result; @@ -205,6 +199,18 @@ private void ShutdownUiThread() this.Engine.Quit(exitCode); } + private void ShutdownUiThread() + { + try + { + this.dummyWindow?.Invoke(new Action(Application.ExitThread)); + } + catch (Exception e) + { + this.Log("Failed to shutdown TestBA window, exception: {0}", e.Message); + } + } + protected override void OnDetectUpdateBegin(DetectUpdateBeginEventArgs args) { this.Log("OnDetectUpdateBegin");