C# 判断网络是连接到互联网(简单有效)
[System.Runtime.InteropServices.DllImport("wininet")]
private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue);
//判断网络是连接到互联网
public static bool IsNetWorkConnect()
{
int i = 0;
return InternetGetConnectedState(out i, 0) ? true : false;
}
使用:
if (IsNetWorkConnect())
MessageBox.Show("已连接到互联网");
else
MessageBox.Show("无网络");

浙公网安备 33010602011771号