几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量

几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 (http://www.dimcax.com/hust/index.php)
-   C# (http://www.dimcax.com/hust/forumdisplay.php?f=147)
-   -   【转帖】c#: 网络状态 (http://www.dimcax.com/hust/showthread.php?t=1237)

yogy 2007-08-01 02:06 PM

【转帖】c#: 网络状态
 
[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;
}
}
}


所有的时间均为北京时间。 现在的时间是 02:21 PM.