Browse Source

抄写线程在当前窗口只能单开,多开导致异常。

Jeff 2 years ago
parent
commit
8d54201bba
1 changed files with 6 additions and 1 deletions
  1. 6 1
      FactoryTool_CShare/Views/OperationPanel.cs

+ 6 - 1
FactoryTool_CShare/Views/OperationPanel.cs

@@ -47,6 +47,8 @@ namespace MOKA_Factory_Tools
         Thread SNTextFocus;
         bool FocusMark = false;
         Thread WritekeyThread;
+        // 线程锁:当前窗口抄写线程只能开一个;
+        private readonly object WriteKeyThreadLock;
         string availableCount = "unknow";
         // 只有NTF才用该变量, 0试产, 1=量产;
         int nOrderType = -1;
@@ -104,6 +106,7 @@ namespace MOKA_Factory_Tools
                 ProductMsg_Text.Text = "Roku:";
             if (functionSetting.NTF)
                 ntfBLL = new NTFBLL(functionSetting.Mexican_NTF);
+            WriteKeyThreadLock = new object();
         }
 
         /// <summary>
@@ -1741,6 +1744,7 @@ namespace MOKA_Factory_Tools
         /// </summary>
         public void Writekey()
         {
+            Monitor.Enter(WriteKeyThreadLock);
             DateTime startTime = DateTime.Now;
             ArrayList keypath = new ArrayList();
             ArrayList keyStream = new ArrayList();
@@ -1748,7 +1752,7 @@ namespace MOKA_Factory_Tools
             //int SerailDelay = FunctionSettingNow.SerailDelay;
             int SerailDelay = FunctionSettingNow.NextCommandWaitTime;
 
-            Log.WriteInfoLog(SN + "   start testing");
+            Log.WriteInfoLog(string.Format("threadid={0} SN={1}    start testing",SN, Thread.CurrentThread.ManagedThreadId.ToString()));
             // 0表示抄写失败,特殊:上报IDM失败\获取key失败\抄写失败;
             // 1表示抄写成功,特殊:无;
             // 2表示抄写成功,特殊:但试产NTF要求连续2次PASS才能上传MES,需要再测试一次;
@@ -5182,6 +5186,7 @@ namespace MOKA_Factory_Tools
             EnableText(SNText);            
 #endif
             EnableButton(BtnClickstart);
+            Monitor.Exit(WriteKeyThreadLock);
         }
 
         /// <summary>