mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-27 23:11:34 -05:00
fix(ui): validate Nest Info and Edit Plate on the UI thread
Both dialogs revalidated with a System.Timers.Timer whose SynchronizingObject was the form. Before the dialog has a handle, InvokeRequired is false, so the Elapsed handler ran EnableCheck on a pool thread. When the UI thread was busy (for example with the cut simulator open), the timer fired before ShowDialog and touched applyButton while the UI thread was creating it, throwing a cross-thread InvalidOperationException. Use a WinForms timer, which always ticks on the UI thread, and stop starting it from the constructor, which already calls EnableCheck directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
be8d1443e3
commit
5620c9b842
2 files changed
+19
-15
No files matched your search
@@ -2,7 +2,7 @@ using System;
|
||||
using System.Windows.Forms;
|
||||
using OpenNest.Data;
|
||||
using OpenNest.Geometry;
|
||||
using Timer = System.Timers.Timer;
|
||||
using Timer = System.Windows.Forms.Timer;
|
||||
|
||||
namespace OpenNest.Forms
|
||||
{
|
||||
@@ -23,14 +23,16 @@ namespace OpenNest.Forms
|
||||
statusBox.Items.Add(status);
|
||||
statusBox.SelectedItem = NestStatus.Quote;
|
||||
|
||||
timer = new Timer
|
||||
// A WinForms timer ticks on the UI thread. System.Timers.Timer's SynchronizingObject
|
||||
// cannot marshal before the dialog has a handle, so a busy UI thread (e.g. an open
|
||||
// cut simulator) let it run EnableCheck on a pool thread while the handle was created.
|
||||
timer = new Timer { Interval = SystemInformation.KeyboardDelay + 1 };
|
||||
timer.Tick += (sender, e) =>
|
||||
{
|
||||
SynchronizingObject = this,
|
||||
Enabled = true,
|
||||
AutoReset = false,
|
||||
Interval = SystemInformation.KeyboardDelay + 1,
|
||||
timer.Stop();
|
||||
EnableCheck();
|
||||
};
|
||||
timer.Elapsed += (sender, e) => EnableCheck();
|
||||
Disposed += (sender, e) => timer.Dispose();
|
||||
nameBox.TextChanged += (sender, e) => EnableCheck();
|
||||
EnableCheck();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using Timer = System.Timers.Timer;
|
||||
using Timer = System.Windows.Forms.Timer;
|
||||
|
||||
namespace OpenNest.Forms
|
||||
{
|
||||
@@ -17,14 +17,16 @@ namespace OpenNest.Forms
|
||||
|
||||
this.plate = plate;
|
||||
|
||||
timer = new Timer
|
||||
// A WinForms timer ticks on the UI thread. System.Timers.Timer's SynchronizingObject
|
||||
// cannot marshal before the dialog has a handle, so a busy UI thread (e.g. an open
|
||||
// cut simulator) let it run EnableCheck on a pool thread while the handle was created.
|
||||
timer = new Timer { Interval = SystemInformation.KeyboardDelay + 1 };
|
||||
timer.Tick += (sender, e) =>
|
||||
{
|
||||
SynchronizingObject = this,
|
||||
Enabled = true,
|
||||
AutoReset = false,
|
||||
Interval = SystemInformation.KeyboardDelay + 1,
|
||||
timer.Stop();
|
||||
EnableCheck();
|
||||
};
|
||||
timer.Elapsed += (sender, e) => EnableCheck();
|
||||
Disposed += (sender, e) => timer.Dispose();
|
||||
|
||||
Load(plate);
|
||||
EnableCheck();
|
||||
|
||||
Reference in new issue
Block a user