private void ExecuteCommand() { int receivedLength = clientSocket.Receive(receiveBuffer); clientCommand = Encoding.UTF8.GetString(receiveBuffer).Substring(0, receivedLength); if (clientCommand == "[<Close/>]") { return; } MemoryStream ms = new MemoryStream(receiveBuffer, 0, receivedLength); BinaryFormatter formatter = new BinaryFormatter(); //ms.Position = 0; for (int i = 1; ms.Position < ms.Length; i++) { UserCommandBase userCommand = (UserCommandBase)(formatter.Deserialize(ms)); userCommand.Execute(); ms.Position = i * 512; this.Dispatcher.Invoke(() => txtCommandExecutor.AppendText(userCommand.ToString() + "\n")); } }