c#判断是否有网络

//调用操作系统API  
[System.Runtime.InteropServices.DllImport("wininet")]
private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue);
      

/// <summary>
        /// 判断是否链接到外网
        /// </summary>
        public static bool IsNetWorkConnect()
        {
            int i = 0;
            return InternetGetConnectedState(out i, 0) ? true : false;
        }

  

posted @ 2019-04-19 11:16  韩梦芫  阅读(1414)  评论(0编辑  收藏  举报