c# - Determine if internet connection is available -


I know that I am not the first to ask questions: How do I know if my application is online or not? I found this post: I want to do it with C # and .NET 3.5.

The recommendation is to ping the resource on a regular basis. I am not very happy with that advice. Instead I find a network change and then ping my service to check whether it is online.

.NET provides two events for this purpose: NetworkChange.Network Change the changeable network. Network address changed

The first event looks good but it only gets removed When the last network card becomes offline online I have several virtual network cards installed by VMWare and they are always online but the second event works but the network cable and During touching the event, there are often 5 seconds waiting time. When I unplug the cable, the Windows Tray icon immediately gives more or less feedback, what is the best way to stay fast as a tray icon?

My solution will be to select the network interface in every 500 mms and to throw off my own event, the position of the network adapter has changed.

There should be a better solution :)

I've suggested the link Webleeuw , But when I plug or unplug my cable, that code requires between 4 and 10 seconds, to inform me now, I want to know that this is just my computer or installation and I have my own The supervisor class is based on the network interface. Gate LNetwork Interface ()

And: It works with lightning speed. My app now responds to the same reaction as the tray does now, the code is far from the code of production, it's just a quick hack, but this is what I will create now :)

  Tax; Using System.Net.NetworkInformation; Timer = By using the system. threading. Timer; Namespace NetworkCrackup {public class networkStats observer} {public event event handler < EventAgds> NetworkChanged; Private Network Interface [] Old Interface; Private Timer Timer; Public Zero Start () {Timer = New Timer (Update Network Stats, Blank, New Timespace (0, 0, 0, 0, 500), New TimeSpain (0, 0, 0, 0, 500)); OldInterfaces = NetworkInterface.GetAllNetworkInterface (); } Private Zero UpdateNetworkStatus (object o) {var newInterfaces = NetworkInterface.GetAllNetworkInterface (); Bool is changed = false; If (new interface lang! = Old interface. Lang) {has changed = change; } If (! Hashings) {for (int i = 0; i & lt; old interface.lambi; i ++) {if (old interface [i] .name! = New interface [i] .name {old} Interface [I]. Operative Status! New Interface [i]. Operational Status) {hasChanges = true; break; }}} OldInterfaces = newInterface; If (has changed) {RaiseNetworkChanged (); }} Private Zero Risennet changed () (if changed (Network changed! =) {Network changed. Invoke (this, blank)}}}}  
Click

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -