我的目标是检测以太网电缆何时断开我正在尝试使用NetworkChange
类,但是当我拔下以太网电缆时该事件NetworkAvailibilityChanged
不会触发。NetworkAddressChanged
确实会在大约 8 秒内触发,但NetworkAvailibilityChanged
从来没有,我有什么遗漏吗?
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");
}
}