--: Thread updateThread = new Thread(updateList);//更新列表线程--
updateThread.IsBackground = true;
updateThread.Start();
二: private void updateList()
{
while (!stopInventoryFlag)//未停止
{
updateInventoryGridList();
Thread.Sleep(500);
if (this.lstSeminRecord?.Count==0)
{
sleepTime = 3000;
Thread.Sleep(sleepTime);
}
}
}
三: private void updateInventoryGridList()
{
//防止感应的架位被阻塞,及时释放感应到的架位
while (inventoryTagQueue.Count > 0 && this.lstSeminRecord?.Count == 0)//&& StopFlag == false
{
lock (lockObj)
inventoryTagQueue.Dequeue();
if (inventoryTagQueue.Count==0)
{
return;
}
Thread.Sleep(1);
}
UHFOperDelegate updateForm = delegate ()
{
while (inventoryTagQueue.Count > 0 && this.lstSeminRecord?.Count>0 )//&& StopFlag == false
{
Tag packet;
packet = inventoryTagQueue.Dequeue();
if (packet != null)
{
String epc = packet.EPC;
if (epc.Length != 24 ) //不是24位字符位乱码字符
{
continue;
}
if (epc != tempEpc)
{
tempCount = 0;
tempEpc = epc;
}
if (tempEpc == this.lastLoctor)
{
tempCount = 0;
continue;
}
tempCount++;
if (tempCount != 3)
{
continue;
}
if (this.lastLoctor== epc)
{
continue; //不能连续扫描同一个架位信息
}
//tag EPC值转换为库位
// StopFlag = true;
string locator = Util.FormatEpcLoctor(epc);
//根据库位找到对应子库
string subInv = svs.GetSubInv(locator);
//验证架位信息(1是否存在,2架位是否存在于该仓库)
if (svs.GetLocalQty(subInv, locator) > 0)
{
//DotNetSpeech.SpeakAsync("架位已占用,请更换架位");
this.lblRkStatus.Text = "入库失败";
this.lblRkStatus.Update();
this.lbllogs.Text = "架位已占用,请更换架位并联系仓库保管进行确认";
this.lbllogs.Update();
return;
}
//更新架位信息
this.txtLocator.Text = locator;
this.txtLocator.Update();
this.lblRssi.Text = packet.RSSI.ToString() ;
this.lblRssi.Update();
//dgv遍历执行入库(分为带合并码和不带合并码)
Dictionary<string, string> dic = new Dictionary<string, string>();
foreach (SeminRecode semiObj in this.lstSeminRecord)
{
semiObj.Receive_locator = locator;
dic = svs.SeminEexcute(semiObj);
if (dic["flag"] != "S")
{
//DotNetSpeech.SpeakAsync("警告上架数据异常");
this.lblRkStatus.Text = "上架数据异常";
this.lblRkStatus.Update();
this.lbllogs.Text = dic["message"];
this.lbllogs.Update();
rkStatus = false;
rfidDetectFlag = false;
break ;
}
else
{
rkStatus = true;
}
//RfidSqlRecordIn(locator, semiObj.Batch_num);插入半成品入库记录 正式时启用
}
if (rkStatus)
{
//解析为windows应用
myPlay = new SoundPlayer(System.Windows.Forms.Application.StartupPath + @"/钟声.wav");
myPlay.PlaySync();
// DotNetSpeech.SpeakAsync("上架成功");
this.lblRkStatus.Text = "上架成功";
this.lblRkStatus.Update();
this.lbllogs.Text = "成功" ;
this.lbllogs.Update();
this.lastLoctor = epc;
ResetContent();
}
tempTagCount = 0;
//this.Invoke(new UHFOperDelegate(updateInventoryGridList)); //执行委托--间歇性扫描同步单独线程即可
}
Thread.Sleep(1);
}
};
if (this.IsHandleCreated)
{
this.Invoke(updateForm);
}
}
哪位能帮解决下。
updateThread.IsBackground = true;
updateThread.Start();
二: private void updateList()
{
while (!stopInventoryFlag)//未停止
{
updateInventoryGridList();
Thread.Sleep(500);
if (this.lstSeminRecord?.Count==0)
{
sleepTime = 3000;
Thread.Sleep(sleepTime);
}
}
}
三: private void updateInventoryGridList()
{
//防止感应的架位被阻塞,及时释放感应到的架位
while (inventoryTagQueue.Count > 0 && this.lstSeminRecord?.Count == 0)//&& StopFlag == false
{
lock (lockObj)
inventoryTagQueue.Dequeue();
if (inventoryTagQueue.Count==0)
{
return;
}
Thread.Sleep(1);
}
UHFOperDelegate updateForm = delegate ()
{
while (inventoryTagQueue.Count > 0 && this.lstSeminRecord?.Count>0 )//&& StopFlag == false
{
Tag packet;
packet = inventoryTagQueue.Dequeue();
if (packet != null)
{
String epc = packet.EPC;
if (epc.Length != 24 ) //不是24位字符位乱码字符
{
continue;
}
if (epc != tempEpc)
{
tempCount = 0;
tempEpc = epc;
}
if (tempEpc == this.lastLoctor)
{
tempCount = 0;
continue;
}
tempCount++;
if (tempCount != 3)
{
continue;
}
if (this.lastLoctor== epc)
{
continue; //不能连续扫描同一个架位信息
}
//tag EPC值转换为库位
// StopFlag = true;
string locator = Util.FormatEpcLoctor(epc);
//根据库位找到对应子库
string subInv = svs.GetSubInv(locator);
//验证架位信息(1是否存在,2架位是否存在于该仓库)
if (svs.GetLocalQty(subInv, locator) > 0)
{
//DotNetSpeech.SpeakAsync("架位已占用,请更换架位");
this.lblRkStatus.Text = "入库失败";
this.lblRkStatus.Update();
this.lbllogs.Text = "架位已占用,请更换架位并联系仓库保管进行确认";
this.lbllogs.Update();
return;
}
//更新架位信息
this.txtLocator.Text = locator;
this.txtLocator.Update();
this.lblRssi.Text = packet.RSSI.ToString() ;
this.lblRssi.Update();
//dgv遍历执行入库(分为带合并码和不带合并码)
Dictionary<string, string> dic = new Dictionary<string, string>();
foreach (SeminRecode semiObj in this.lstSeminRecord)
{
semiObj.Receive_locator = locator;
dic = svs.SeminEexcute(semiObj);
if (dic["flag"] != "S")
{
//DotNetSpeech.SpeakAsync("警告上架数据异常");
this.lblRkStatus.Text = "上架数据异常";
this.lblRkStatus.Update();
this.lbllogs.Text = dic["message"];
this.lbllogs.Update();
rkStatus = false;
rfidDetectFlag = false;
break ;
}
else
{
rkStatus = true;
}
//RfidSqlRecordIn(locator, semiObj.Batch_num);插入半成品入库记录 正式时启用
}
if (rkStatus)
{
//解析为windows应用
myPlay = new SoundPlayer(System.Windows.Forms.Application.StartupPath + @"/钟声.wav");
myPlay.PlaySync();
// DotNetSpeech.SpeakAsync("上架成功");
this.lblRkStatus.Text = "上架成功";
this.lblRkStatus.Update();
this.lbllogs.Text = "成功" ;
this.lbllogs.Update();
this.lastLoctor = epc;
ResetContent();
}
tempTagCount = 0;
//this.Invoke(new UHFOperDelegate(updateInventoryGridList)); //执行委托--间歇性扫描同步单独线程即可
}
Thread.Sleep(1);
}
};
if (this.IsHandleCreated)
{
this.Invoke(updateForm);
}
}
哪位能帮解决下。
能说的详细点么?万分感谢。刚接触多线程,本来以为很简单,就按硬件提供的Demo写了,结果