5236
Pathfinder; After Machine Configuration or Option Changed Pathfinder Freezes
Pathfinder

Changes made for Pathfinder V5 PC's.

Problem Pathfinder froze when changing machine configuration or machine options. The app would show the "Pathfinder will now restart" dialog, but after dismissing it, the window would hang and never restart.

Root Cause The freeze was caused by CloseCommDevice() deadlocking on _lock in FoldbusEthernet_IO — the queue thread was stuck inside SendCommand() holding that same lock, and no amount of signaling could make it release the lock fast enough because StopMessagePump() Join timeouts would expire first. Additionally, Application.Restart() triggered a re-entrant shutdown cascade through form closing events.

Files Changed

  1. QueueManager.cs — Check _stopCommRequested at the top of every loop iteration and after acquiring the mutex / completing ProcessCommand(), so the queue thread exits promptly during shutdown instead of only checking when the queue is empty. Made _stopCommRequested volatile.

  2. StatusRequestCO.cs — Changed context.Send() to context.Post() in EventProcessingLoop and added a _eventThreadShouldStop guard. Prevents deadlock between the event processing thread (waiting for UI thread) and the UI thread (waiting for event thread to stop).

  3. FoldbusEthernet_IO.cs — Set ReceiveTimeout = 1000 on the UDP client so Receive() throws after 1 second instead of blocking forever. Wired up the previously empty SetResponseTimeout() method.

  4. ControllerRunStateCommManager.cs — Added overload SetControllerToPowerDown(out ManualResetEvent) that returns the command's Processed handle so callers can wait for completion.

  5. MachineCommunicationManager.cs — Added PowerDown(out ManualResetEvent) overload. Added StopCommunication(bool closeCommDevice) overload that skips CloseCommDevice during restart (avoiding the deadlock). Set StopCommunicating = true as the first action in StopCommunication so UDP send/receive loops bail out immediately.

  6. FoldingMachinePhysicalDevice.cs — Made stopCommunicating field volatile for cross-thread visibility.

  7. ApplicationManager.cs — RestartPathfinder() now waits up to 3s for the PowerDown command to complete, uses StopCommunication(closeCommDevice: false) to avoid the lock deadlock, and uses Process.Start() + Environment.Exit(0) instead of Application.Restart() to avoid the re-entrant form-closing shutdown cascade. Same PowerDown wait added to ExitPathfinder(). Added using System.Diagnostics.

Model Version Released
Pathfinder PC 5.01.42.3681 2/27/2026