如何去检测网络的连接状态(C#)
2006-03-15 10:04
621 查看
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#中如何判断已知网络的连接状态?(2)
- C#检测当前网络连接状态
- [原创]Coding4Fun检测你的网络,用C#获取本机TCP、UDP状态及连接(一)
- C#检测网络的连接状态
- [原创]Coding4Fun检测你的网络,用C#获取本机TCP、UDP状态及连接(二)
- C#编程:网络连接状态的定时检测
- C#如何检测网络端口连接的状态
- 如何去检测网络的连接状态
- C#检测网络的连接状态
- c#中如何判断已知网络的连接状态?
- C#如何去检测网络的连接状态
- 检测网络连接状态_转
- iOS下的实际网络连接状态检测(转)
- 如何检查Android网络连接状态
- IOS检测网络连接状态
- Android 检测网络连接状态
- iOS下的实际网络连接状态检测:RealReachability