/// <summary> /// 执行和设备的通信线程: 需要保证同一个IP的是在同一个线程之中进行执行 /// </summary> private void RunThread() { var token = _cancellationTokenSource.Token; while (true) { if (token.IsCancellationRequested) { break; } DeviceCommunication cur = null; lock (_communicationListLock) { if (_communicationList.Count > 0) { cur = _communicationList.Dequeue(); } } if (cur != null) { cur.DoCommunication(token); } // System.Threading.Thread.Sleep(10); } }
public void Add(DeviceCommunication c) { lock (_communicationListLock) { _communicationList.Enqueue(c); } }