public void ConnectButton() { int parsedPort = Int32.Parse(PortNumber); ServerConnection.ServerIP = new IPEndPoint(IPAddress.Parse(SelectedIP), parsedPort); ServerConnection.ConnectionSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); ServerConnection.ConnectToServer(Nickname); //NotifyOfPropertyChange(() => CanConnectButton); if (ServerConnection.ConnectionSocket.Connected) { Thread thread = new Thread(() => ServerConnection.BeginListening()); thread.IsBackground = true; thread.Start(); } }