From 78289c64a16dd02cc9fec595bf758a9e30a30926 Mon Sep 17 00:00:00 2001
From: patrick.xu <patrick.xu@broconcentric.com>
Date: 星期六, 20 二月 2021 10:51:11 +0800
Subject: [PATCH] gocator修改异步模式下图片获取操作

---
 src/Bro.M071.Process/M071Process.cs |   58 ++++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 46 insertions(+), 12 deletions(-)

diff --git a/src/Bro.M071.Process/M071Process.cs b/src/Bro.M071.Process/M071Process.cs
index 7666577..f7b3f92 100644
--- a/src/Bro.M071.Process/M071Process.cs
+++ b/src/Bro.M071.Process/M071Process.cs
@@ -199,9 +199,9 @@
         List<ProductionMeasurement> productionList = new List<ProductionMeasurement>();
 
         bool _isdoing = false;
+        object _doingLock = new object();
 
         [ProcessMethod("", "StartJob", "寮�濮嬫壂鎻�", InvokeType.TestInvoke)]
-        [MethodImpl(MethodImplOptions.Synchronized)]
         public ProcessResponse StartJob(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
         {
             if (!IsAllowedWork)
@@ -226,7 +226,16 @@
                 throw new ProcessException(hint);
             }
 
-            _isdoing = true;
+            lock (_doingLock)
+            {
+                if (_isdoing)
+                {
+                    LogAsync(DateTime.Now, "璁惧姝e湪杩愯涓�", "");
+                    return new ProcessResponse(true);
+                }
+
+                _isdoing = true;
+            }
 
             MachineState = MachineState.Running;
 
@@ -272,7 +281,9 @@
             pMeasure.InitialMeasurementsPropertyChanged();
             pMeasure.PropertyChanged += MeasureProduction_PropertyChanged;
 
-            Config.SnapshotPointCollection.Where(u => u.IsEnabled).ToList().ForEach(s =>
+            try
+            {
+                Config.SnapshotPointCollection.Where(u => u.IsEnabled).ToList().ForEach(s =>
                   {
                       _pausedHandle.Wait();
 
@@ -321,26 +332,42 @@
 
                       RunImageHandle(s.CameraOp.OpConfig, set, s.Id, s.Name, pMeasure.Measurements);
                   });
+            }
+            catch (Exception ex)
+            {
+                throw ex;
+            }
+            finally
+            {
+                LogAsync(DateTime.Now, $"{pMeasure.Barcode}娴嬮噺鍔ㄤ綔瀹屾垚", "");
+                _isdoing = false;
 
-            LogAsync(DateTime.Now, $"{pMeasure.Barcode}娴嬮噺鍔ㄤ綔瀹屾垚", "");
-            _isdoing = false;
-
-            GC.Collect(0, GCCollectionMode.Optimized);
+                GC.Collect(0, GCCollectionMode.Optimized);
+            }
 
             return new ProcessResponse(true);
         }
 
         #region 鍙屾墜鍚姩
+        object _leftStartLock = new object();
+        object _rightStartLock = new object();
+
         bool isLeftStart = false;
         bool IsLeftStart
         {
             get => isLeftStart;
             set
             {
-                if (IsLeftStart != value)
+                if (isLeftStart != value)
                 {
-                    isLeftStart = value;
-                    StartCheck();
+                    lock (_leftStartLock)
+                    {
+                        if (IsLeftStart != value)
+                        {
+                            isLeftStart = value;
+                            StartCheck();
+                        }
+                    }
                 }
             }
         }
@@ -353,14 +380,21 @@
             {
                 if (isRightStart != value)
                 {
-                    isRightStart = value;
-                    StartCheck();
+                    lock (_rightStartLock)
+                    {
+                        if (isRightStart != value)
+                        {
+                            isRightStart = value;
+                            StartCheck();
+                        }
+                    }
                 }
             }
         }
 
         private void StartCheck()
         {
+
             if (isRightStart && isLeftStart)
             {
                 if (_isdoing)

--
Gitblit v1.8.0