locked
NetworkInformation.NetworkStatusChanged does not work on Surface RRS feed

  • Question

  • I created a very simple C# windows store app to get the internet connection status, but found out that it only works on my PC, but not in my tablet Surface.  I tested it by disconnecting and connecting my Wifi connection.  Here is the code.

           
            public MainPage()
            {
                this.InitializeComponent();
                NetworkInformation.NetworkStatusChanged += NetworkInformation_NetworkStatusChanged;
            }
    
            void NetworkInformation_NetworkStatusChanged(object sender)
            {
                Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                    () =>
                    {
                        int tc = System.Environment.TickCount;
                        ConnectionProfile profile = NetworkInformation.GetInternetConnectionProfile();
                        MessageBlock.Text += string.Format("{0}{1}\n", System.Environment.TickCount - tc, profile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess);
                    }).AsTask().ConfigureAwait(false);
    
            }
    
            private void Button_Click(object sender, RoutedEventArgs e)
            {
                int tc = System.Environment.TickCount;
                ConnectionProfile profile = NetworkInformation.GetInternetConnectionProfile();
                MessageBlock.Text += string.Format("->{0}{1}\n", System.Environment.TickCount - tc, profile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess);
            }

    In my tablet, it only receive connected event, but not disconnected event.  Any idea? thank you so much in advance.

     

     

     

     

     

    Tuesday, October 1, 2013 4:10 AM

Answers

  • Found the issue.  Looks like the ARM based tablet behaves differently than x86 based PC.  NetworkInformation.GetInternetConnectionProfile() returns null on Windows RT when internet connection is off.  In x86 based, the profile returns NetworkConnectivityLevel.None in GetNetworkConnectivityLevel().  

    Now I assume there is no internet connection when the profile is null.

    • Marked as answer by Albert Pun Tuesday, October 1, 2013 6:15 PM
    Tuesday, October 1, 2013 6:15 PM

All replies

  • Found the issue.  Looks like the ARM based tablet behaves differently than x86 based PC.  NetworkInformation.GetInternetConnectionProfile() returns null on Windows RT when internet connection is off.  In x86 based, the profile returns NetworkConnectivityLevel.None in GetNetworkConnectivityLevel().  

    Now I assume there is no internet connection when the profile is null.

    • Marked as answer by Albert Pun Tuesday, October 1, 2013 6:15 PM
    Tuesday, October 1, 2013 6:15 PM
  • Thanks.
    Sunday, November 23, 2014 4:43 PM