network change event/Compare
-
I'm trying to detect when an ethernet cable is unplugged from a computer or plugged back in. I have some devices that when plugged in they come up as Unidentified Network(which is normal for the specific device). I'm not looking for internet connection or have anything to do with that. And I think this code works as a trigger:
NetworkChange.NetworkAddressChanged += new NetworkAddressChangedEventHandler(NetworkChange_NetworkAddressChanged);
private static void NetworkChange_NetworkAddressChanged(object sender, EventArgs e)
{NetworkInterface\[\] adapters = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface n in adapters) { MessageBox.Show(n.Name.ToString() + n.OperationalStatus.ToString()); }
}
What I need to do now is to figure out which network adapter was unplugged. I intend to get the operational status of each network adapter. Store it, ask user to power cycle the device and then compare with the stored value(s) to figure out which one has changed from up to down. I'm not sure what the best method to do this would be. Should I do this as an array, list or is there an easier way?
-
I'm trying to detect when an ethernet cable is unplugged from a computer or plugged back in. I have some devices that when plugged in they come up as Unidentified Network(which is normal for the specific device). I'm not looking for internet connection or have anything to do with that. And I think this code works as a trigger:
NetworkChange.NetworkAddressChanged += new NetworkAddressChangedEventHandler(NetworkChange_NetworkAddressChanged);
private static void NetworkChange_NetworkAddressChanged(object sender, EventArgs e)
{NetworkInterface\[\] adapters = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface n in adapters) { MessageBox.Show(n.Name.ToString() + n.OperationalStatus.ToString()); }
}
What I need to do now is to figure out which network adapter was unplugged. I intend to get the operational status of each network adapter. Store it, ask user to power cycle the device and then compare with the stored value(s) to figure out which one has changed from up to down. I'm not sure what the best method to do this would be. Should I do this as an array, list or is there an easier way?