Im trying to show a message to the user when connection to the internet is lost
I have this method on my App.xaml.cs
static async void NetworkInformation_NetworkStatusChanged(object sender)
{
//Get the Internet connection profile
//ConnectionProfile connectionProfileInfo = null;
try
{
ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();
if (InternetConnectionProfile == null)
{
ApplicationData.Current.LocalSettings.Values["INTERNET"] = false;
ShowBox("Internet Lost");
Frame rootFrame = Window.Current.Content as Frame;
rootFrame.Navigate(typeof(LoginPage));
}
else
{
ApplicationData.Current.LocalSettings.Values["INTERNET"] = true;
}
}
catch (Exception ex)
{
Debug.WriteLine("Unexpected exception occurred: " + ex.ToString());
}
}
and this other one
public async static void ShowBox(string msg)
{
try
{
await new MessageDialog(msg, "No Internet").ShowAsync();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
}
}
When i cause a connection lost ( disable my internet connection ) the ShowBox method gets called, and i get this exception on it:
Invalid window handle.
This API must be called from a thread with a CoreWindow or a window must have been set explicitly.
Is there any way to show a MessageDialog from that event?