0

I tried to find the answer, but I failed. When Internet connection is not available the icon on the Window's notification area has yellow mark. When Internet becomes available the a yellow mark disappears. I want to get notified at that moment.

The following is only for Ethernet connection, not actual Internet availability. I need a event to detect Internet connect/disconnect

I could not find how to use NetworkInformation.NetworkStatusChanged in WinForms.

Other than constantly pinging some web site myself, is there a cleaner solution? All the answers I found were old. The OS must already know whether Internet is available or not, because it changed the notification area icon. How can I get that information from the OS?

I am using .NET Framework 4.7.

It seems my question would be closed. But this is not a duplicate of that, because that question was checking for Internet, and mine is getting notified at the moment.

Damn Vegetables
  • 11,484
  • 13
  • 80
  • 135
  • http://windowsapptutorials.com/windows-10/how-to-check-for-network-availability-in-universal-windows-apps/ for UWP otherwise...well just P/Invoke the good old `IsInternetConnected()` – Adriano Repetti Aug 28 '17 at 10:56
  • Can I use that in WinForms, not in UWP? – Damn Vegetables Aug 28 '17 at 10:58
  • 1
    @DamnVegetables _"...otherwise...well just P/Invoke the good old `IsInternetConnected()`"_! Note that to determine if Internet is available and if it's working and you have the desired access are two different things but most of times you don't really care about that difference. Note: if you have a problem with `NetworkChange` notifications then you should describe that problem and provide code you're using. – Adriano Repetti Aug 28 '17 at 11:02
  • Please understand that I added that comment before you modified the comment. – Damn Vegetables Aug 28 '17 at 11:05
  • There is no built-in function to do that, you should use some workaround like sending a ping or making some web request and regular interval to check this. If you want to copy Windows behavior you could have a look on http://blog.superuser.com/2011/05/16/windows-7-network-awareness/ **Remarks : As the OS notifiy the user about that, most of time you don't have to do it.** – Marco Guignard Aug 28 '17 at 11:15

0 Answers0