欢迎光临
我们一直在努力

如何去检测网络的连接状态(C#)-.NET教程,C#语言

建站超值云服务器,限时71元/月

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;

}

}

}

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 如何去检测网络的连接状态(C#)-.NET教程,C#语言
分享到: 更多 (0)