C# NetworkAvailibilityChanged doesn't trigger on disconnect
Posted
by
Nickolay Kondratyev
on Stack Overflow
See other posts from Stack Overflow
or by Nickolay Kondratyev
Published on 2012-10-14T21:34:28Z
Indexed on
2012/10/14
21:36 UTC
Read the original article
Hit count: 198
My goal is to detect when the Ethernet cable gets disconnected I am attempting to use NetworkChange
class but the event NetworkAvailibilityChanged
does not trigger when I unplug Ethernet cable. NetworkAddressChanged
does get triggered in about 8 seconds but NetworkAvailibilityChanged
never does, is there is anything am I am missing?
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
NetworkChange.NetworkAvailabilityChanged += new NetworkAvailabilityChangedEventHandler(NetworkChange_NetworkAvailabilityChanged);
NetworkChange.NetworkAddressChanged += new NetworkAddressChangedEventHandler(NetworkChange_NetworkAddressChanged);
}
void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
{
Console.WriteLine("NetworkChange_NetworkAvailabilityChanged");
}
void NetworkChange_NetworkAddressChanged(object sender, EventArgs e)
{
Console.WriteLine("NetworkChange_NetworkAddressChanged");
}
}
© Stack Overflow or respective owner