C#检测网络的连接状态
2011-09-29 15:20
441 查看
1. 方法定义
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState( out int connectionDescription, int reservedValue ) ;
2. 方法说明
参数:
connectionDescription : 连接说明
reservedValue : 保留值
返回值:
true: On Line
false: Off Line
3. 调用方法
a. 你必须在你的code里引用System.Runtime.InteropServices,否则,会有编译错误
b. 定义一个变量 int I = 0;
c. 调用bool state = InternetGetConnectedState(out I,0);
完整的代码:
using System.Runtime.InteropServices;
namespace internet
{
public class Class1
{
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState( out int connectionDescription, int reservedValue ) ;
public Class1(){}
private bool IsConnected()
{
int I=0;
bool state = InternetGetConnectedState(out I,0);
return state;
}
}
}
用勤奋之这石,补能力之缺口!
相关文章推荐
- 如何去检测网络的连接状态(C#)
- [原创]Coding4Fun检测你的网络,用C#获取本机TCP、UDP状态及连接(二)
- C#检测网络的连接状态
- C#如何检测网络端口连接的状态
- C#编程:网络连接状态的定时检测
- [原创]Coding4Fun检测你的网络,用C#获取本机TCP、UDP状态及连接(一)
- 如何去检测网络的连接状态(C#)
- C#检测当前网络连接状态
- 如何去检测网络的连接状态(C#)
- c#使用winnet检测网络连接状况
- iOS下的实际网络连接状态检测
- iOS下的实际网络连接状态检测
- C#使用Ping功能判断网络连接状态或者目标计算机是否开机等
- 李洪强iOS下的实际网络连接状态检测
- C#中判断系统的网络连接状态的方法
- IOS检测网络连接状态
- android中检测网络连接状态简单总结
- IOS检测网络连接状态
- 检测网络连接状态
- C#获取网络状态是否有网络连接