c# vs2010 winfrom控件检测网络环境

时间:2023-12-10 12:46:44

写下以作备用,代码附上。

 public partial class UserControl1 : UserControl, IObjectSafety
{
//检测网络状态
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue);
/// <summary>
/// 检测网络状态
/// </summary>
private bool isConnected()
{
int I = ;
bool state = InternetGetConnectedState(out I, );
return state;
}
    private void update_Load(object sender, EventArgs e)
{
if (isConnected())
{
//network is connected.
}
else
{
//network is not connected.
}

     }