public Task StartReceived() { while (true) { var stream = _client.GetStream(); stream.Read(_messageLength, 0, _messageLength.Length); var data = new byte[BitConverter.ToInt32(_messageLength, 0)]; stream.Read(data, 0, data.Length); var message = new Message(); message.ReadBytes(data); if (MessageReceived != null) { var thread = new Thread(() => MessageReceived(this, message)); thread.Start(); } } }
public void SendMessage(Message message) { this.messageQueue.Enqueue(message); }