2

私は次の方法を持っています:

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 ( InternectConnectionProfileis null) が返されます。何故ですか?どうすれば修正できますか?

4

3 に答える 3

4

インターネット上のサーバーにpingを実行することを検討してください。これはあなたの質問に対する100%の答えではありませんが、別の観点から役立つかもしれません。

using System.Net;
using System.Net.NetworkInformation;

using (Ping Packet = new Ping()) 
{
    if (Packet.Send(IPAddress.Parse(IP), 1000, new byte[] { 0 }).Status ==   IPStatus.Success))
    {
       // ...
    }
}
于 2012-08-01T10:27:11.510 に答える
2

試す

public static bool IsConnectedToInternet()
{
        ConnectionProfile connectionProfile = NetworkInformation.GetInternetConnectionProfile();
        return (connectionProfile!=null && connectionProfile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess);
}
于 2012-11-29T12:06:21.677 に答える
1

これはあなたに役立つかもしれません

于 2012-08-01T10:21:28.817 に答える