public void Listen() { TcpListener tcpListener = new TcpListener(IPHelper.GetIPAddress(), Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["Port"])); tcpListener.Start(); while (IsLive) { string str = TCPHelper.TCPRecevier(tcpListener); if (str == System.Configuration.ConfigurationManager.AppSettings["TCPSTOP"]) { tcpListener.Stop(); tcpListener.Server.Close(); IsLive = false; continue; } if (!string.IsNullOrEmpty(str)) { if (this.mainForm != null) { //mainForm.ThreadFunction(str); } } } }