首页 / 软件开发 / C# / C#检测网络的连接状态
C#检测网络的连接状态2009-11-03x1. 方法定义[DllImport("wininet.dll")]private extern static bool InternetGetConnectedState( out int connectionDescription, int reservedValue ) ;2. 方法说明参数:connectionDescription : 连接说明reservedValue : 保留值返回值:true: On Linefalse: Off Line3. 调用方法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;
}
}
}
用勤奋之这石,补能力之缺口!