From 1769b8907d036a787110fafd34d12501cd2ecafb Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Mon, 5 Oct 2026 21:27:42 -0400 Subject: [PATCH] fix(ui): post cutting-plan progress and results to the dialog thread The dialog relied on Progress and an await continuation capturing SynchronizationContext.Current when planning started. WinForms uninstalls its ambient context when the outermost DoEvents loop ends, so a plan started outside a message loop reported progress from a thread-pool thread and crashed the test host with "Error creating window handle" (windows-desktop job of run 37398775280, CuttingPlanFormTests.ApplyAfterALiveEdit_ChangesNothingAndReplanRecovers). Capture the dialog's context once when it is built and post progress and the finished plan to it explicitly. The busy-editor test now starts planning after a DoEvents loop to cover that path. --- .../Forms/CuttingPlanFormTests.cs | 3 + OpenNest/Forms/CuttingPlanForm.cs | 63 +++++++++++-------- 2 files changed, 41 insertions(+), 25 deletions(-) diff --git a/OpenNest.WinForms.Tests/Forms/CuttingPlanFormTests.cs b/OpenNest.WinForms.Tests/Forms/CuttingPlanFormTests.cs index 7d80dff..9794032 100644 --- a/OpenNest.WinForms.Tests/Forms/CuttingPlanFormTests.cs +++ b/OpenNest.WinForms.Tests/Forms/CuttingPlanFormTests.cs @@ -138,6 +138,9 @@ public class CuttingPlanFormTests Assert.Null(form.Proposal); Assert.Contains("Wait for the current nesting or plate action", Control(form, "summaryBox").Text); busy = false; + // Ending a DoEvents loop uninstalls WinForms' ambient context; planning started outside a + // message loop must still report progress and results on the dialog's thread. + Application.DoEvents(); Invoke(form, "StartPlanning"); PumpUntil(() => form.Proposal != null, "the plan"); Assert.True(Control