在.NET中检查Internet连接的最快,最有效的方法是什么?
我有这个方法:
public static void testConnection()
{
if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
{
System.Windows.MessageBox.Show("This computer is connected to the internet");
}
else
{
System.Windows.MessageBox.Show("This computer is not connected to the internet");
}
}
Run Code Online (Sandbox Code Playgroud)
我想它会告诉我连接是否可用但它总是返回true(并打印第一条消息),即使我确定没有连接.我做错了什么?
PS:我还在学习C#.