public ResResultModel SaveBarcodeScanQueue(BarcodeScanQueueModel model) { try { var list = new List <ComboboxInfo>(); var bsaBll = new BarcodeScanAsyn(); var sItemBody = HttpUtility.UrlDecode(model.ItemBody); new CustomException(sItemBody); if (model.From == EnumData.EnumStep.架.ToString()) { List <ShelfMissionProductQueueInfo> smpList = JsonConvert.DeserializeObject <List <ShelfMissionProductQueueInfo> >(sItemBody); if (smpList != null && smpList.Count > 0) { foreach (var item in smpList) { bsaBll.Insert(new BarcodeTypeInfo(model.From, JsonConvert.SerializeObject(item))); list.Add(new ComboboxInfo { Id = item.Id.ToString(), Text = "1" }); } } } return(ResResult.Response(true, "", JsonConvert.SerializeObject(list))); } catch (Exception ex) { return(ResResult.Response(false, ex.Message, "")); } }
public void WorkProcess() { try { // the transaction timeout should be long enough to handle all of orders in the batch TimeSpan tsTimeout = TimeSpan.FromSeconds(Convert.ToDouble(transactionTimeout * batchSize)); var bsBll = new BarcodeScanAsyn(); var taskBll = new DoTask(); while (true) { // queue timeout variables TimeSpan datetimeStarting = new TimeSpan(DateTime.Now.Ticks); double elapsedTime = 0; var listBarcode = new List <BarcodeTypeInfo>(); for (int j = 0; j < batchSize; j++) { try { //only receive more queued orders if there is enough time if ((elapsedTime + queueTimeout + transactionTimeout) < tsTimeout.TotalSeconds) { listBarcode.Add(bsBll.ReceiveFromQueue(queueTimeout)); } else { j = batchSize; // exit loop } //update elapsed time elapsedTime = new TimeSpan(DateTime.Now.Ticks).TotalSeconds - datetimeStarting.TotalSeconds; } catch (TimeoutException) { //exit loop because no more messages are waiting j = batchSize; } } if (listBarcode.Count > 0) { taskBll.DoBarcode(listBarcode); } } } catch (Exception ex) { new CustomException(string.Format("来自{0}异常:{1}", "BarcodeScan", ex.Message), ex); } }