如何去检测网络的连接状态
2007-09-16 14:07
435 查看
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;
}
}
}
[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#如何检测网络端口连接的状态
- 如何去检测网络的连接状态(C#)
- 如何去检测网络的连接状态(C#)
- C#如何检测网络端口连接的状态
- C#如何去检测网络的连接状态
- 如何去检测网络的连接状态(C#)
- IOS检测网络连接状态(转)
- APP 检测网络的状态 是wifi 还是蜂窝连接
- IOS检测网络连接状态
- c#中如何判断已知网络的连接状态?
- Android如何获取网络连接状态(3G/Wifi)及怎样调用网络配置界面
- C#编程:网络连接状态的定时检测
- IOS检测网络连接状态(转)
- C#检测当前网络连接状态
- [IOS 开发] AFNetworking2.2 setReachabilityStatusChangeBlock检测网络连接状态
- 网络连接状态检测的一个方法
- 检测本地网络连接状态断开以及恢复的方法
- 实时检测网络状态及是否可以连接Internet
- IOS检测网络连接状态
- qt检测网络连接状态【只能检测和路由器的连接,不能测试到外网的连接】