How to detect Network Instability with C#

Asked

Viewed 94 times

2

I have a Winforms system where the folders that this system generates and uses stay on a server, but there are some routines of this system that keep creating several PDF’s on the server, and when any instability occurs in the network it does not create some PDF’s. I wonder if there is any Framework that detects instability or drop in the network and warns the user or manages it, someone has heard of something like this. If at the time the system is using the server the network crashes or crashes anything the routine will warn or wait to generate when it returns to normal.

  • 1

    The framework for this is .NET. What you can do is Try-catch every time you save the files (you probably already do some treatment that way).

  • 1

    You can also use a timer to ping the server every ten seconds, and raise an alert if you can’t reach it.

  • Currently I use the System.Net.NetworkInformation.Ping to precisely ping the server, and only continue in case the Address is different from null.

  • Creates a file generation request queue, and while the file is not successfully generated you keep looping in that queue. When the network starts working again the files will be generated.

1 answer

2


From Framework 2.0 you can with GetIsNetworkAvailable():

System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()

To monitor IP changes or whether you’re logged in or not, use Networkchange class events:

System.Net.NetworkInformation.NetworkChange.NetworkAvailabilityChanged
System.Net.NetworkInformation.NetworkChange.NetworkAddressChanged

Browser other questions tagged

You are not signed in. Login or sign up in order to post.