How do you determine if an Internet connection is available for your WinForms App?

前端 未结 8 804
生来不讨喜
生来不讨喜 2020-12-24 15:33

What is the best way to determine whether there is an available Internet connection for a WinForms app. (Programatically of course) I want to disable/hide certain functions

8条回答
  •  生来不讨喜
    2020-12-24 16:25

    A guess at Internet connectivity would be network availability, at NetworkInterface.GetIsNetworkAvailable(). The events on NetworkChange can tell you when it changes. Both classes are in the System.Net.NetworkInformation namespace.

    Of course, you won't know if the Internet is really available until you try to connect to something.

提交回复
热议问题