NetworkInterface.GetIsNetworkAvailable()与DeviceNetworkInformation.IsNetworkAvailable

时间:2012-01-06 01:04:48

标签: windows-phone-7.1 windows-phone-7

DeviceNetworkInformation.IsNetworkAvailable

    // Summary:
    //     Gets a value that indicates whether the network is available.
    //
    // Returns:
    //     true if there is at least one network interface available; otherwise, false.
    public static bool IsNetworkAvailable { get; }

NetworkInterface.GetIsNetworkAvailable()

    // Summary:
    //     Indicates whether any network connection is available.
    //
    // Returns:
    //     true if a network connection is available; otherwise, false.
    [SecuritySafeCritical]
    public static bool GetIsNetworkAvailable();

这些相同吗?

1 个答案:

答案 0 :(得分:7)

Microsoft wants you to use DeviceNetworkInformation.IsNetworkAvailable

NetworkInterface位于System.NetDeviceNetworkInformation位于Microsoft.Phone.Net.NetworkInformation

DeviceNetworkInformation.IsNetworkAvailable可能会在内部映射到NetworkInterface.GetIsNetworkAvailable(),但您应始终使用DeviceNetworkInformation.IsNetworkAvailable,因为它是为手机制作的(并且具有更清晰的API)。

正如Matthieu所指出的,DeviceNetworkInformation.IsNetworkAvailable在7.1(芒果)中显然是新的。