I'm a bit of newbie to c#/.net development, but I've put together a stock tracking application for a small set of assets in my company. I have also set up the database it connects to in SQL 2000.
It currently works brilliantly when a network connection is available, but I want to expand it for use when I'm away from a connection.
First off I'll need to know if there's a connection available. So I put this together:
private int availableNetAdapters()
{
int nicCount = 0;
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
if (nic.OperationalStatus == OperationalStatus.Up)
{
nicCount++;
}
}
return nicCount;
}
Seems to work, but I have to test for ">1" as something as "MS TCP Loopback interface" is always detected regardless of the other adapter sates.
Is there a better/easier way to check connectivity?
G