查看文章 |
C# 判断计算机网络是否可用
2007-12-12 11:21
首先添加引用: using System.Runtime.InteropServices; 代码: [DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue);
private static bool IsConnected() {
int I = 0;
bool state = InternetGetConnectedState(out I, 0);
return state;
} 使用方法: textBox1.Text = IsConnected().ToString();
这样就可以返回一个Bool值,表示目前网络的状态。 |
最近读者: