C# 判断计算机网络是否可用

 

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();

你可能感兴趣的:(网络,C#,textbox)