I need to get current connection state.
I found: System.Net.NetworkInformation.NetworkChange.NetworkAvailabilityChanged event but how can I get current network state ?
I need to get current connection state.
I found: System.Net.NetworkInformation.NetworkChange.NetworkAvailabilityChanged event but how can I get current network state ?
Take a look at the code on MSDN here, http://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkchange.aspx. It show how to query the network adapters to determine their state.
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);
}
}
}