-1

I would like to ask that how can I do a continuously internet connection checking in my UWP apps and shows warning dialog which allow the apps to be idle when the apps is disconnect? This is because when internet is disconnected, as there are many function require internet connection, so the apps just quit by itself without any notification. So far I know how to check the connection but not continuously.

private void CheckInternetAndShowDialog()
            {
                bool isConnected = NetworkInterface.GetIsNetworkAvailable();
                if (isConnected)
                {
                    textBlock1.Text = "Is Connected";
                }
                else
                {
                    textBlock1.Text = "Disconnected";
                }

            }
Chen L
  • 1
  • 4
  • Possible duplicate of [What is the best way to implement a "timer"?](https://stackoverflow.com/questions/12535722/what-is-the-best-way-to-implement-a-timer) – Progman May 11 '19 at 08:59

1 Answers1

0

There is a NetworkStatusChanged event on the NetworkInformation class that sounds like it's what you're looking for. So you can subscribe to that event when your UWP app starts and use the following code to check whether or not you have a network connection when the status changes and then act accordingly.

NetworkInformation.NetworkStatusChanged += NetworkInformation_NetworkStatusChanged;

Michael Xu
  • 4,382
  • 1
  • 8
  • 16