[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("无网络");
标签:C#,网络,int,互联网,InternetGetConnectedState,连接,out From: https://www.cnblogs.com/microsoft-zh/p/16884314.html