c# 判断网络是否中断

后台:

        [DllImport("wininet.dll")]
        private extern static bool InternetGetConnectedState(int description, int reservedValue);
        /// <summary>
        /// 判断当前网络状况
        /// </summary>
        /// <returns></returns>
        public static bool IsConnectedToInternet()
        {
            return InternetGetConnectedState(0, 0);
        }

调用:

       if (!WebHelper.IsConnectedToInternet())
         {
               MessageBox("网络连接中断,请检查网络状态!");
                return;
         }

原文地址:https://www.cnblogs.com/yonguibe/p/2832752.html