private void listUpdate() { while (waitingForStart) { NetworkStream serverStream = clientSocket.GetStream(); if (!waitingForStart) { break; } byte[] inStream = new byte[3]; //msg code serverStream.Read(inStream, 0, 3); string returndata = System.Text.Encoding.ASCII.GetString(inStream); string returnUser; if (returndata == "108") { inStream = new byte[1]; //number of users serverStream.Read(inStream, 0, 1); returndata = System.Text.Encoding.ASCII.GetString(inStream); Invoke((MethodInvoker) delegate { roomPlayers.Items.Clear(); }); for (int i = 0; i < int.Parse(returndata); i++) //loop for number of users { string user; inStream = new byte[2]; //2 bytes for size of room name serverStream.Read(inStream, 0, 2); returnUser = System.Text.Encoding.ASCII.GetString(inStream); //user name size inStream = new byte[int.Parse(returnUser)]; //size of room name serverStream.Read(inStream, 0, int.Parse(returnUser)); returnUser = System.Text.Encoding.ASCII.GetString(inStream); user = returnUser; Invoke((MethodInvoker) delegate { roomPlayers.Items.Add(user); }); } } else if (returndata == "116" && !isAdmin) //admin closed the room { Invoke((MethodInvoker) delegate { msgToUser.Text = "The admin closed the room press OK to continue"; leaveCloseB.Text = "OK"; waitingForStart = false; }); } else if (returndata == "118") { Invoke((MethodInvoker) delegate { gameStarted = true; Form GameForm = new Game(clientSocket, menu, true, questionsNumber, questionTimeInSec); GameForm.Show(); this.Close(); }); } } }