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

后端 未结 27 2515
感动是毒
感动是毒 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:28

    You can use NetworkInterface.GetIsNetworkAvailable method which indicates whether any network connection is available.

    Try this:

    bool connection = NetworkInterface.GetIsNetworkAvailable();
    if (connection == true)
     {
         MessageBox.Show("The system is online");
     }
     else {
         MessageBox.Show("The system is offline";
     }
    

提交回复
热议问题