I need to detect the Ethernet cable disconnection in the system, for the same I'm using the following code to detect the changes in all the networks available in the system.
using System;
using System.Net;
using System.Net.NetworkInformation;
namespace Examples.Net.AddressChanges
{
public class NetworkingExample
{
public static void Main()
{
NetworkChange.NetworkAddressChanged += new
NetworkAddressChangedEventHandler(AddressChangedCallback);
Console.WriteLine("Listening for address changes. Press any key to exit.");
Console.ReadLine();
}
static void AddressChangedCallback(object sender, EventArgs e)
{
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface n in adapters)
{
Console.WriteLine(" {0} is {1}", n.Name, n.OperationalStatus);
}
}
}
}
My requirement, is to run a set of code when the "operational status" of "Ethernet" is "down" and another set of code when the "operational status" of "Ethernet" is "Up".
I'm pretty new to this, so I'm not able to use the operational status to do the required programming. Can anyone please help me with this?