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;
         }

你可能感兴趣的:(C#)