日期:2014-05-17  浏览次数:20786 次

点击文中的button后,在socket连接不通的情况下,所在的form窗体会假死。该如何解决此问题?
点击文中的button后,在socket连接不通的情况下,所在的form窗体会假死。该如何解决此问题?  

 
    private void okBtn_Click(object sender, EventArgs e)
        {
            this.ip = ipTB.Text;
            String port = portTB.Text;
            this.path = textBox1.Text;
            if (this.ip == "" || port == "" || this.path == "")
            {
                showLB1.Text = "ip,port和文件的输入框不能为空!";
                showLB1.Refresh();
            }
            else
            {
                this.port = int.Parse(port);
                try
                {
                lable:
                    //创建终结点EndPoint
                    IPAddress ipaddress = IPAddress.Parse(this.ip);
                    IPEndPoint ipe = new IPEndPoint(ipaddress, this.port);

                    //创建Socket并连接到服务器
                    Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);   //  创建Socket
                    showLB1.Text = "Connecting...";
                    showLB1.Refresh();