日期:2014-05-17 浏览次数:20830 次
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;
}
}