检查网络是否可以连接互联网

来源:互联网 发布:数据产品经理书籍推荐 编辑:程序博客网 时间:2024/04/27 00:09

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime;
using System.Runtime.InteropServices;

namespace SmsSoft
{
    public class CheckInternetConnection
    {
        /// <summary>
        /// 用于检查网络是否可以连接互联网,true表示连接成功,false表示连接失败
        /// </summary>
        /// <returns></returns>
        [DllImport("wininet.dll")]
        private extern static bool InternetGetConnectedState(int Description, int ReservedValue);
        public static bool CheckConnection()
        {       
            int Description = 0;
            return InternetGetConnectedState(Description, 0);
        }


    }
}