public void Join() { try { _is_running = verification() ? true : throw new Exception($"{Id} is not chat client."); while (IsClientConnected() && _is_running) { if (_stream.DataAvailable) { // десиарелизация сообщения BinaryFormatter formatter = new BinaryFormatter(); ClientMessage newMessage = (ClientMessage)formatter.Deserialize(_stream); ClientOutgoingMessageEvent?.Invoke(this, newMessage); } Thread.Sleep(10); } } catch (Exception ex) { _is_running = false; ClientErrorEvent?.Invoke(this, ex); } finally { _tcp_client?.Close(); ClientDisconnectEvent?.Invoke(this, null); } }