c# vs2010 winfrom控件检测网络环境

时间:2014-07-03 11:22:39   收藏:0   阅读:238

写下以作备用,代码附上。

 public partial class UserControl1 : UserControl, IObjectSafety
    {
        //检测网络状态
        [DllImport("wininet.dll")]
        private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue);
        /// <summary>
        /// 检测网络状态
        /// </summary>
        private bool isConnected()
        {
            int I = 0;
            bool state = InternetGetConnectedState(out I, 0);
            return state;
        }
     private void update_Load(object sender, EventArgs e)
        {
            if (isConnected())
            {
            //network  is connected.
            }
            else
            {
             //network is not connected.
             }

     }

 

c# vs2010 winfrom控件检测网络环境,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!