C#检测当前网络连接状态
来源:互联网 发布:开机windows update 编辑:程序博客网 时间:2024/06/05 10:42
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#如何去检测网络的连接状态
- C#编程:网络连接状态的定时检测
- C#检测网络连接
- 监测当前网络连接状态
- Android 检测网络连接状态
- Android 检测网络连接状态
- Android 检测网络连接状态
- IOS检测网络连接状态
- IOS检测网络连接状态
- IOS检测网络连接状态
- Modify in the AVL report,and refresh to the internal table
- weblogic和tomcat的区别
- 诗一首
- 使用异步选择函数WSAAsyncSelect
- C#遍历文件
- C#检测当前网络连接状态
- C++ Builder 2007 -- Vista之后,托管还是原生?
- 人生如梦游戏间,JAVA游戏开源开发讲座[番外篇]之AVG开发——皮影
- linux C + mysql 找不到lmysqlclient库
- LFS中遇到的问题
- 自定义应用程序配置文件(app.config)
- Update-FormatData 帮助信息
- htmlTable 模拟实现datagrid等的部分功能.
- An old article about OpenBSD project & Theo