void rxThread() { while (true) { if (DriverManager.IsInitialized) { int dataSize = DriverManager.Driver.GetQueue().Count; if (dataSize > 0) { try { for (int i = 0; i < dataSize; i++) { CANData cd = DriverManager.GetData(); ctvr.Dispatcher.Invoke(new Action(() => { ctvr.appendData(cd); })); mlt.Dispatcher.Invoke(new Action(() => { mlt.addItem(cd.ToString()); })); rxTime.Enqueue(cd.ActionTime); } } catch { return; } } } DateTime histLimit = DateTime.Now - new TimeSpan(0, 0, 3); while (rxTime.Count > 0) { if (rxTime.Dequeue() >= histLimit) { break; } } if (rxTime.Count > 0) { long dt = rxTime.Last().Ticks - rxTime.First().Ticks; double dtms = dt / 10000.0 / 1000.0; if (dt == 0) { lbSpeed.Text = "传输速度:- fps"; } else { lbSpeed.Text = string.Format("传输速度:{0} fps", (long)(rxTime.Count / dtms)); } } else { lbSpeed.Text = "传输速度:0 fps"; } lbAllCount.Text = string.Format("总数量:{0}条 ", ctvr.Data.Count); Thread.Sleep(50);//20Hz刷新率 } }