首页 > 编程语言 >C# 判断网络是连接到互联网(简单有效)

C# 判断网络是连接到互联网(简单有效)

时间:2022-11-12 18:00:49浏览次数:29  
标签:C# 网络 int 互联网 InternetGetConnectedState 连接 out

[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

相关文章