日期:2014-05-20  浏览次数:20959 次

怎么实现C#判断连网状态
C# code

[DllImport("wininet")]
        private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue);

使用了这个方法一点用也没有,永远放回为true,我的是Win7系统,另外使用如果建议使用ping就算了吧,以为我做的是网络数据采集程序,ping命令会干扰程序的采集的质量

------解决方案--------------------
C# code

int i = 0;
if (InternetGetConnectedState(out i, 0))
{
    MessageBox.Show("联网状态");
}
else
{
    MessageBox.Show("你网线掉了啦");
}