日期:2014-05-18  浏览次数:20729 次

询问一个关于异步socket编程的问题,主要是关于waitone()函数的问题
贴出一部分代码   大家看下
                ///   <summary>
                ///   开始监听
                ///   </summary>
                private   void   StartListen()
                {
                        try
                        {
                                if   (!this.IsStoped)
                                {
                                        this.Msg.Text= "连接尝试中... ";
                                        this._Connected   =   false;
                                        IPHostEntry   ipHostInfo   =   Dns.GetHostEntry(this.ServerAddress);
                                        IPAddress   ipAddress   =   ipHostInfo.AddressList[0];
                                        IPEndPoint   remoteEP   =   new   IPEndPoint(ipAddress,   this.ServerPort);

                                       
                                        this.Client   =   new   Socket(AddressFamily.InterNetwork,   SocketType.Stream,   ProtocolType.Tcp);

                                        this.Client.BeginConnect(remoteEP,   new   AsyncCallback(ConnectCallback),   Client);
                                        connectDone.WaitOne();//在这里阻塞主线程
                                        MessageBox.Show( "退出 ");
                                }
                        }
                        catch   (Exception   e)
                        {
                                this.SetText( "