zoukankan      html  css  js  c++  java
  • c# 判断网络是连接到互联网




            [System.Runtime.InteropServices.DllImport("wininet")]
            private extern static bool InternetGetConnectedState(out int connectionDescriptionint reservedValue);
           
            private void button1_Click(object senderEventArgs e)
            {
                int i = 0;
                if (InternetGetConnectedState(out i, 0))
                    MessageBox.Show("联网状态");
                else
                    MessageBox.Show("你网线掉了啦");
            }

    修改下 
           [System.Runtime.InteropServices.DllImport("wininet")]
            private extern static bool InternetGetConnectedState(out int connectionDescriptionint reservedValue);
            //判断网络是连接到互联网
            public static bool IsNetWorkConnect()
            {
                int i = 0;
              return InternetGetConnectedState(out i, 0) ? true:false;
            }

              
                if ( IsNetWorkConnect() )
                    MessageBox.Show("已连接到互联网");
                else
                    MessageBox.Show("无网络")









  • 相关阅读:
    算法系列:杂项
    算法系列:
    Algo: Dynamic programming
    Algo:
    算法系列:XXX
    算法系列:量子计算与量子通信
    算法系列:Reservoir Sampling
    算法系列:CSAPP 推荐
    算法系列:
    算法系列:geometry
  • 原文地址:https://www.cnblogs.com/xe2011/p/3761951.html
Copyright © 2011-2022 走看看