What's the easiest way to verify there's an available network connection?

前端 未结 4 635
小蘑菇
小蘑菇 2021-02-04 14:43

I\'m a bit of newbie to c#/.net development, but I\'ve put together a stock tracking application for a small set of assets in my company. I have also set up the database it conn

4条回答
  •  醉话见心
    2021-02-04 15:02

    System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()

    You can also use the events NetworkAvailabilityChanged and NetworkAddressChanged in that class to monitor IP address and network availability changes.

    EDIT: Be aware that this method checks all available network interfaces that may be on the computer (wireless, lan, etc.). If anyone of them is connected, it will return true.

提交回复
热议问题