【发布时间】:2012-08-01 10:14:42
【问题描述】:
我有以下方法:
public static bool IsNetworkConnected()
{
ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();
IReadOnlyList<ConnectionProfile> connectionProfile = NetworkInformation.GetConnectionProfiles();
if (InternetConnectionProfile == null)
return false;
else
return true;
}
当我以典型方式(通过 LAN 电缆或 Wi-Fi)连接到互联网时,它工作正常。当我使用我的 3G USB 调制解调器时,它返回 false(InternectConnectionProfile 为空)。这是为什么?我该如何解决?
【问题讨论】:
-
我通常建议您忽略当前的连接状态,并尝试通过 Internet 执行您想做的任何事情(最好在后台线程中) - 然后向用户报告,如果在(超时时间/重试次数)之后,您无法完成任务。在检查它们的存在和使用它们之间,或者在你正在做的任何任务中途,连接可能会中断。由于您必须编写代码来应对这些情况无论如何,请节省一些编码并避免预先检查。
标签: c# windows-8 microsoft-metro windows-runtime