C# NetworkAvailibilityChanged doesn't trigger on disconnect
- by Nickolay Kondratyev
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");
}
}