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

posted @ 2012-12-25 17:14  沙漠绿洲uibe  阅读(724)  评论(0编辑  收藏  举报