从网上找到两种检测网络连接状态的方法,做个备份。
第一种,利用ping类
bool bolPing = true;//标识量
System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();System.Net.NetworkInformation.PingReply pingReply = ping.Send(System.Net.IPAddress.Parse("202.108.22.5"), 500);//Ping百度,500毫秒超时
//判断ping返回来的结果
bolPing = (pingReply.Status == System.Net.NetworkInformation.IPStatus.Success);
if (bolPing)
{
MessageBox.Show("网络连接正常");
}
第二种,利用WindowsAPI
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(int Description, int ReservedValue);
private void button1_Click(object sender, EventArgs e)
{
bool bolConnect =