diff --git a/TBF/BenchControl/Operations/CheckUIOp.cs b/TBF/BenchControl/Operations/CheckUIOp.cs index ca4ad90b9..f651de58d 100644 --- a/TBF/BenchControl/Operations/CheckUIOp.cs +++ b/TBF/BenchControl/Operations/CheckUIOp.cs @@ -55,12 +55,12 @@ namespace TBF.BenchControl.Operations public Event Run() { - if (Bridge.Ui2MachineQueue.Count <= 0) return Event.None; - UI2BenchCmd cmd; lock (Bridge.Ui2MachineQueue) { + if (Bridge.Ui2MachineQueue.Count <= 0) return Event.None; + if (Bridge.Ui2MachineQueue.Contains(UI2BenchCmd.Stop)) { do { @@ -68,6 +68,13 @@ namespace TBF.BenchControl.Operations } while (cmd != UI2BenchCmd.Stop); } + else if (Bridge.Ui2MachineQueue.Contains(UI2BenchCmd.Shutdown)) + { + do { + cmd = Bridge.Ui2MachineQueue.Dequeue(); + } + while (cmd != UI2BenchCmd.Shutdown); + } else { cmd = Bridge.Ui2MachineQueue.Dequeue(); diff --git a/TBF/BenchControl/Sequences/MainSeq.cs b/TBF/BenchControl/Sequences/MainSeq.cs index ec3f7ec80..06affd381 100644 --- a/TBF/BenchControl/Sequences/MainSeq.cs +++ b/TBF/BenchControl/Sequences/MainSeq.cs @@ -1178,6 +1178,8 @@ namespace TBF.BenchControl.Sequences { log.WarnFormat("MakeSelection({0})", context); + IOperation checkUiOpWithClear = new Operations.CheckUIOp(true); + bool shutdownInProgress = false; /// Tank emptying valves states @@ -1222,7 +1224,7 @@ namespace TBF.BenchControl.Sequences State.Create("MainSeq : Select an activity") - .AddOperation(checkUiOp) + .AddOperation(checkUiOpWithClear) .AddOperation((StateMachine.Scale1 != null) ? StateMachine.Scale1.ReadMassOp(ref mass1) : null) .AddOperation((StateMachine.Scale2 != null) ? StateMachine.Scale2.ReadMassOp(ref mass2) : null) .AddOperation((StateMachine.Scale3 != null) ? StateMachine.Scale3.ReadMassOp(ref mass3) : null) @@ -1237,6 +1239,7 @@ namespace TBF.BenchControl.Sequences { #if true /// TBF shutdown without tank draining + log.Fatal("Returning from MakeSelection() after e.Contains(Event.UiCmdShutdown)==true"); return Selection.Shutdown; #else /// TBF shutdown with tank draining diff --git a/TBF/BenchControl/StateMachine.cs b/TBF/BenchControl/StateMachine.cs index ad1b627c0..3a6fba111 100644 --- a/TBF/BenchControl/StateMachine.cs +++ b/TBF/BenchControl/StateMachine.cs @@ -625,7 +625,9 @@ namespace TBF.BenchControl new Sequences.MainSeq().Execute(null); + log.Fatal("StateMachine.Worker() before State.StopOperations()"); State.StopOperations(); + log.Fatal("StateMachine.Worker() after State.StopOperations()"); stateMachineRunning = false; } diff --git a/TBF/MainWnd.cs b/TBF/MainWnd.cs index 4ae98d02a..dbb16165a 100644 --- a/TBF/MainWnd.cs +++ b/TBF/MainWnd.cs @@ -576,12 +576,22 @@ namespace TBF { if (BenchControl.StateMachine.Running) { - Bridge.Ui2Bench(UI2BenchCmd.Shutdown); /// Drain tanks and quit the main sequence + int elapsedTimeMs; do { - Thread.Sleep(100); + Bridge.Ui2Bench(UI2BenchCmd.Shutdown); /// Quit the main sequence, optionally drain tanks + elapsedTimeMs = 0; + do + { + Thread.Sleep(100); + elapsedTimeMs += 100; + } + while (BenchControl.StateMachine.Running && elapsedTimeMs < 3000); /// Wait until StateMachine.Worker() completes + + if (elapsedTimeMs < 3000) break; } - while (BenchControl.StateMachine.Running); /// Wait until StateMachine.Worker() completes + while (elapsedTimeMs >= 3000); /// Keep resending UI2BenchCmd.Shutdown on 3s timeouts (BenchControl.StateMachine.Running stays true for 3s) + /// Show 'Closing_Test_Bench_Framework' modeless window in separate thread var form = new TBF.Forms.ModelessActivityForm() diff --git a/TBF/Properties/AssemblyInfo.cs b/TBF/Properties/AssemblyInfo.cs index 3e890bbfa..29325d8a0 100644 --- a/TBF/Properties/AssemblyInfo.cs +++ b/TBF/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("2.18.812.0")] -[assembly: AssemblyFileVersion("2.18.812.0")] +[assembly: AssemblyVersion("2.18.813.0")] +[assembly: AssemblyFileVersion("2.18.813.0")]