what is the reliable way of checking network availability change in c# WPF application? Currently, I am using NetworkChange Class and NetworkAvailabilityChanged event to detect the network availability change. But the event is not getting triggered if the connection is disconnected.
Asked
Active
Viewed 304 times
0
-
According to the documentation you only need one network connected for it to be 'available'. Do you have more than one network connected? (possibly WiFi + wired connection). https://learn.microsoft.com/en-us/dotnet/api/system.net.networkinformation.networkchange.networkavailabilitychanged?view=netcore-3.1 – Simon Bosley Oct 05 '20 at 12:06
-
Maybe you could do some periodical check of the network state, and then in case of change - send event to all target processes. – kosist Oct 05 '20 at 12:06
-
@SimonBosley I need to check whether the user is connected to the net or not? As soon as he gets connected/disconnected from the net an event should get triggered informing the user is connected or disconnected – user3722329 Oct 05 '20 at 12:26
-
@user3722329 I was wondering if possibly you were testing this by disconnecting a network cable (but whilst having WiFi still connected) that could possibly cause it not to fire event notification to NetworkAvailabilityChanged. Can you provide your code so we can see what you're doing? – Simon Bosley Oct 05 '20 at 12:28
-
@SimonBosley Actually I need a code to check whether the user is connected to net or not? If the user gets connected/disconnected from wifi/LAN (i.e if the network connectivity gets changed) then it should trigger an event where it gives information whether user is connected to net or not? – user3722329 Oct 05 '20 at 12:55
-
@user3722329 - Look at this post: [How do I check for a network connection?](https://stackoverflow.com/questions/520347/how-do-i-check-for-a-network-connection). If the NetworkAvailabilityChanged event is not triggered you need to provide the [MCVE](https://stackoverflow.com/help/minimal-reproducible-example). – Jackdaw Oct 05 '20 at 17:21