void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Cancelled) { Messages.Items.Add("Disconnecting..."); //string MessageToSend = Message.Text; //ChatWindow.Items.Add("Client(JA): " + MessageToSend); byte[] MessageConverted = Encoding.ASCII.GetBytes("Close Connection"); try { ns.Write(MessageConverted, 0, MessageConverted.Length); } catch (Exception ex) { Messages.Items.Add(ex.ToString()); } } else { if (Game1.GameStarted) { WinConditionWihoutDisconnect(); } if (Game1.GameStarted) { MessageBox.Show("Player has disconnected"); } } Game1.EndGame(); DrawBoardandPawns(Game1.Pawns, Game1.BoardColor); if (ns != null) { ns.Close(); Messages.Items.Add("NetworkStream Closed"); } if (client != null) { client.Close(); Messages.Items.Add("Client Closed"); // MessageBox.Show("Numbers between 0 and 10000 divisible by 7: " + e.Result); } }