日期:2014-05-18 浏览次数:21060 次
//检测网络连接是否连接到Internet
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue);
public bool IsConnected()
{
int connectionDescription = 0;
//判断是否连接到外网上的函数,并返回布尔值
return InternetGetConnectedState(out connectionDescription, 0);
}
------解决方案--------------------
这样不能判断连接到外网吗?
------解决方案--------------------
BOOL InternetGetConnectedStateEx(
__out LPDWORD lpdwFlags,
__out LPTSTR lpszConnectionName,
__in DWORD dwNameLen,
__in DWORD dwReserved
);
------解决方案--------------------
private void button1_Click(object sender, EventArgs e)
{
bool flag = IsConnected();
MessageBox.Show(flag.ToString());
}
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue);
public bool IsConnected()
{
int connectionDescription = 0;
//判断是否连接到外网上的函数,并返回布尔值
return InternetGetConnectedState(out connectionDescription, 0);
}
------解决方案--------------------
我试了可以啊,把直接断网后就是false了
InternetGetConnectedState这个就是判断是否连接Internet的API函数,方法肯定没错的
------解决方案--------------------
学习
------解决方案--------------------
更详细的方法,搂主可以看看下面网页:
http://www.zdwork.cn/content/20084/68.htm
------解决方案--------------------
学习了哈`````````
------解决方案--------------------
学习了
------解决方案--------------------
最绝的办法不如搂主直接Ping 百度或google之类的网站
.net下使用System.Net.NetworkInformation.Ping的Send方法
ping.Send("www.google.cn",......)
------解决方案--------------------