public void Send(SignalizationCommand c) { var packet = new SignalizationPacket { Command = c }; lock (packetsQueueSyncObj) { packetsToSend.Enqueue(packet); } }
private void listenTaskRoutine() { CancellationToken token = cancellationTokenSrc.Token; try { string buffer = string.Empty; using (BinaryReader reader = new BinaryReader(stream)) { while (!token.IsCancellationRequested) { bool wait = true; lock (tcpReadWriteSyncObj) { if (stream.DataAvailable) { wait = false; buffer += reader.ReadString(); int pos; while ((pos = buffer.IndexOf(END)) != -1) { var packet = SignalizationPacket.FromXml(buffer.Substring(0, pos)); buffer = buffer.Remove(0, pos + END.Length); while (OnNewPacketIncome == null) { Thread.Sleep(100); } OnNewPacketIncome(this, packet); } } } if (wait) { Thread.Sleep(100); } } } } catch { } }