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

问个关于Ping类的问题
先看我的代码

        private void commTest()
        {
            using (System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping())
            {
                ping.PingCompleted += ping_PingCompleted;
                ping.SendAsync(_ip, null);     
             }
        }
        private void ping_PingCompleted(object sender, System.Net.NetworkInformation.PingCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                _isConnected = false;
                labelStatus.Text = "连接测试被取消";
                return;
            }
            if (e.Error != null)
            {
                labelStatus.Text = e.Error.Message;
                _isConnected = false;
                return;
            }
            if (e.Reply.Status == System.Net.NetworkInformation.IPStatus.Success)
            {
                labelStatus.Text = "已连接";
                _isConnected = true;
                return;
            }
            else
            {
                labelStatus.Text = "连接错误";
                _isConnected = false;
                return;
            }
        }


这样写的话,在我自己的机器上试了很多次一点问题没有,但是用到客户的机器上ping另外一个机器就会直接进入e.cancelled分支。
请问这是为什么?