[chronojump] Programs quits correctly if user closes software while capturing



commit faaeb690e5b3a872af10a120fa04c7577f75c4df
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon May 24 13:29:48 2021 +0200

    Programs quits correctly if user closes software while capturing

 src/gui/app1/chronojump.cs  |  4 +++-
 src/gui/app1/forceSensor.cs | 48 +++++++++++++++++++++++++--------------------
 2 files changed, 30 insertions(+), 22 deletions(-)
---
diff --git a/src/gui/app1/chronojump.cs b/src/gui/app1/chronojump.cs
index 1977afe88..20b1d3736 100644
--- a/src/gui/app1/chronojump.cs
+++ b/src/gui/app1/chronojump.cs
@@ -2547,7 +2547,9 @@ public partial class ChronoJumpWindow
                if(capturingForce == arduinoCaptureStatus.STARTING || capturingForce == 
arduinoCaptureStatus.CAPTURING)
                {
                        LogB.Information("cancelling force capture");
-                       forceProcessCancel = true;
+//                     forceProcessCancel = true;
+                       forceProcessKill = true;
+                       Thread.Sleep(1500); //wait 1.5s to actually thread can be cancelled
                }
                if(forceOtherThread != null && forceOtherThread.IsAlive)
                        forceOtherThread.Abort();
diff --git a/src/gui/app1/forceSensor.cs b/src/gui/app1/forceSensor.cs
index b23d273eb..cebd77e7e 100644
--- a/src/gui/app1/forceSensor.cs
+++ b/src/gui/app1/forceSensor.cs
@@ -69,6 +69,7 @@ public partial class ChronoJumpWindow
        Thread forceCaptureThread;
        static bool forceProcessFinish;
        static bool forceProcessCancel;
+       static bool forceProcessKill; //when user closes program while capturing (do not call arduino and 
wait for its response)
        static bool forceProcessError;
        ForceSensorCapturePoints fscPoints;
 
@@ -1044,6 +1045,7 @@ public partial class ChronoJumpWindow
 
                forceProcessFinish = false;
                forceProcessCancel = false;
+               forceProcessKill = false;
                forceProcessError = false;
 
                //To know if USB has been disconnected
@@ -1240,7 +1242,7 @@ public partial class ChronoJumpWindow
 
                //LogB.Information("pre bucle");
                //LogB.Information(string.Format("forceProcessFinish: {0}, forceProcessCancel: {1}, 
forceProcessError: {2}", forceProcessFinish, forceProcessCancel, forceProcessError));
-               while(! forceProcessFinish && ! forceProcessCancel && ! forceProcessError)
+               while(! forceProcessFinish && ! forceProcessCancel && ! forceProcessKill && ! 
forceProcessError)
                {
                        LogB.Information("at bucle");
                        int time = 0;
@@ -1326,28 +1328,32 @@ public partial class ChronoJumpWindow
                        //changeSlideIfNeeded(time, force);
                }
 
-               //LogB.Information(string.Format("forceProcessFinish: {0}, forceProcessCancel: {1}, 
forceProcessError: {2}", forceProcessFinish, forceProcessCancel, forceProcessError));
-               LogB.Information("Calling end_capture");
-               if(! forceSensorSendCommand("end_capture:", "Ending capture ...", "Catched ending capture"))
-               {
-                       forceProcessError = true;
-                       capturingForce = arduinoCaptureStatus.STOP;
-                       Util.FileDelete(fileName);
-                       return;
-               }
+               if(forceProcessKill)
+                       LogB.Information("User killed the software");
+               else {
+                       //LogB.Information(string.Format("forceProcessFinish: {0}, forceProcessCancel: {1}, 
forceProcessError: {2}", forceProcessFinish, forceProcessCancel, forceProcessError));
+                       LogB.Information("Calling end_capture");
+                       if(! forceSensorSendCommand("end_capture:", "Ending capture ...", "Catched ending 
capture"))
+                       {
+                               forceProcessError = true;
+                               capturingForce = arduinoCaptureStatus.STOP;
+                               Util.FileDelete(fileName);
+                               return;
+                       }
 
-               LogB.Information("Waiting end_capture");
-               do {
-                       Thread.Sleep(10);
-                       try {
-                               str = portFS.ReadLine();
-                       } catch {
-                               LogB.Information("Catched waiting end_capture feedback");
+                       LogB.Information("Waiting end_capture");
+                       do {
+                               Thread.Sleep(10);
+                               try {
+                                       str = portFS.ReadLine();
+                               } catch {
+                                       LogB.Information("Catched waiting end_capture feedback");
+                               }
+                               LogB.Information("waiting \"Capture ended\" string: " + str);
                        }
-                       LogB.Information("waiting \"Capture ended\" string: " + str);
+                       while(! str.Contains("Capture ended"));
+                       LogB.Information("Success: received end_capture");
                }
-               while(! str.Contains("Capture ended"));
-               LogB.Information("Success: received end_capture");
 
                writer.Flush();
                writer.Close();
@@ -1355,7 +1361,7 @@ public partial class ChronoJumpWindow
 
                capturingForce = arduinoCaptureStatus.STOP;
 
-               if(forceProcessCancel || forceProcessError)
+               if(forceProcessCancel || forceProcessKill || forceProcessError)
                        Util.FileDelete(fileName);
                else {
                        //call graph


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]