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 |   70 ++++++++++++++++++++++++++++++----
 1 files changed, 61 insertions(+), 9 deletions(-)

diff --git a/src/Bro.M071.Process/M071Process.cs b/src/Bro.M071.Process/M071Process.cs
index 7165338..f7b3f92 100644
--- a/src/Bro.M071.Process/M071Process.cs
+++ b/src/Bro.M071.Process/M071Process.cs
@@ -48,6 +48,7 @@
         public event Action<IShapeElement> OnElementUpdated;
         public event Action<MachineState> OnMachineStateChanged;
         public event Action OnFullResetDone;
+        public event Action OnResetDone;
         #endregion
 
         string _precision = "f3";
@@ -197,8 +198,10 @@
         object productionLock = new object();
         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)
@@ -207,6 +210,7 @@
             }
 
             string hint = "";
+
             //if (MachineState != MachineState.Ready)
             //{
             //    hint = "鏈哄彴鏈氨缁紝璇峰嬁寮�濮嬫祴閲�";
@@ -220,6 +224,17 @@
                 OnClearBarcode?.Invoke();
                 OnCheckHintUpload?.Invoke(hint, true);
                 throw new ProcessException(hint);
+            }
+
+            lock (_doingLock)
+            {
+                if (_isdoing)
+                {
+                    LogAsync(DateTime.Now, "璁惧姝e湪杩愯涓�", "");
+                    return new ProcessResponse(true);
+                }
+
+                _isdoing = true;
             }
 
             MachineState = MachineState.Running;
@@ -266,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();
 
@@ -315,23 +332,43 @@
 
                       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}娴嬮噺鍔ㄤ綔瀹屾垚", "");
-
-            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
             {
-                isLeftStart = value;
-                StartCheck();
+                if (isLeftStart != value)
+                {
+                    lock (_leftStartLock)
+                    {
+                        if (IsLeftStart != value)
+                        {
+                            isLeftStart = value;
+                            StartCheck();
+                        }
+                    }
+                }
             }
         }
 
@@ -341,15 +378,30 @@
             get => isRightStart;
             set
             {
-                isRightStart = value;
-                StartCheck();
+                if (isRightStart != value)
+                {
+                    lock (_rightStartLock)
+                    {
+                        if (isRightStart != value)
+                        {
+                            isRightStart = value;
+                            StartCheck();
+                        }
+                    }
+                }
             }
         }
 
         private void StartCheck()
         {
+
             if (isRightStart && isLeftStart)
             {
+                if (_isdoing)
+                {
+                    OnCheckHintUpload?.Invoke("璁惧杩愯涓�", false);
+                    return;
+                }
                 StartJob(null, null, null);
             }
         }

--
Gitblit v1.8.0