What is the best way to check for Internet connectivity using .NET?

后端 未结 27 2059
感动是毒
感动是毒 2020-11-22 07:41

What is the fastest and most efficient way to check for Internet connectivity in .NET?

27条回答
  •  花落未央
    2020-11-22 08:37

    private bool ping()
    {
        System.Net.NetworkInformation.Ping pingSender = new System.Net.NetworkInformation.Ping();
        System.Net.NetworkInformation.PingReply reply = pingSender.Send(address);
        if (reply.Status == System.Net.NetworkInformation.IPStatus.Success)
        {                
            return true;
        }
        else
        {                
            return false;
        }
    }
    

提交回复
热议问题