private static void gatherData(object obj) { dtRunHdl = DateTime.Now; while (true) { hdlWh.Reset(); for (int i = 0; i < 200; i++) { if (dvQueue.Count > 0) { break; } dtRunHdl = DateTime.Now; hdlWh.WaitOne(20); } if (dvQueue.Count < 1) { dtRunHdl = DateTime.MinValue; break; } DeviceChannel channel = null; Monitor.Enter(dvQueue); try { channel = dvQueue.Dequeue(); } catch { } Monitor.PulseAll(dvQueue); Monitor.Exit(dvQueue); if (null == channel) { continue; } if (channel.sumRecord > 500) { channel.ClearRecord(); continue; } //采集记录 if (null != channel.cmdGather) { channel.cmdGather.TimeSendInv = channel.tsbusy.Add(channel.tsinv); } else { channel.reChecking(0); } CmdProtocol cmdP = new CmdProtocol(false); setTimeout(cmdP); cmdP.TimeFailLimit = cmdP.TimeOut.Add(new TimeSpan(-10 * 10000)); cmdP.TimeLimit = TimeSpan.MaxValue; cmdP.TimeSendInv = new TimeSpan(1, 0, 0); cmdP.ResponseHandle += new EventHandler <ResponseEventArgs>(channel.execResponse); cmdP.IsResposeHandle = isResponse; cmdP.DeviceType = "通道闸.采集"; string tag = "@设备地址=" + Convert.ToString(channel.station); NameValueCollection datainfo = new NameValueCollection(); for (int i = 0; i < 200; i++) { string msg = channel.getResponse(channel.commimgr, channel.target, cmdP, "读取记录", tag, channel.waitTime); if (string.IsNullOrEmpty(msg)) { continue; } string cardnum = basefun.valtag(msg, "{卡号}"); string suc = basefun.valtag(msg, "Success"); if ("true" != suc || "16777215" == cardnum || "0" == cardnum) { //bool isend = channel.IsEndReadDevice(-1); //记录错误时记入日志,继续下一条 if ("false" == suc) { datainfo["操作"] = "读取记录失败"; datainfo["报文"] = CommandBase.Parse(cmdP.ResponseData, true); ServiceTool.LogMessage(msg, datainfo, EventLogEntryType.FailureAudit); } break; //if (isend) break; } channel.writeRecord(msg); } channel.commimgr.RemoveCommand(channel.target, cmdP); //channel.reChecking(1); if (null != channel.cmdGather) { channel.cmdGather.TimeSendInv = channel.tsinv; } else { channel.reChecking(1); } } }