private void bgWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker bgw = sender as BackgroundWorker; var deviceCache = SV.DeviceDictonary.FirstOrDefault(p => p.Key.Usage == Function); DeviceProxy device = deviceCache.Value; while (true) { if (bgw.CancellationPending) { break; } device.ClearIDBuffer(); List <string> tags = device.EPCMultiTagInventory(); foreach (string tagCode in tags) { TaskItem item = null; if (!SV.TaskQueue.ContainsKey(tagCode)) { //test only item = new TaskItem() { TagCode = tagCode, GoodsType = 1, }; SV.TaskQueue.TryAdd(tagCode, item); #if DEBUG Console.WriteLine($"{Function.ToString()} : " + tagCode); #endif } else { item = SV.TaskQueue[tagCode]; if (item.StatesLog[TaskStates.Dry] != null) { // 表示已走过这个流程 } else { bgw.ReportProgress(2, item); } } } Thread.Sleep(1000); } }
private void bgWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker bgw = sender as BackgroundWorker; var deviceCache = SV.DeviceDictonary.FirstOrDefault(p => p.Key.Usage == Function); DeviceProxy device = deviceCache.Value; while (true) { if (bgw.CancellationPending) { break; } device.ClearIDBuffer(); List <string> tags = device.EPCMultiTagInventory(); foreach (string tagCode in tags) { TaskItem item = null; if (!SV.TaskQueue.ContainsKey(tagCode)) { // test item = new TaskItem() { TagCode = tagCode, GoodsType = 1, //todo: 以后做判断 OrderSN = "ORDER_" + DateTime.Now.ToString("u", DateTimeFormatInfo.InvariantInfo) }; SV.TaskQueue.TryAdd(tagCode, item); //bgw.ReportProgress(2, item); } else { item = SV.TaskQueue[tagCode]; if (item.StatesLog[TaskStates.Wash] != null) { // 表示已走过这个流程 } else { bgw.ReportProgress(2, item); } } } Thread.Sleep(1000); } }