Reputation: 2043
This is a problem i am experiencing in WP 7 app dev. Actually I want to detect the presence of network while the application launches I use this code
bool isNetwork=NetworkInterface.GetIsNetworkAvailable();
if(!isnetwork)
{
MessageBox.Show("No Network Available","App Name",MessageBoxButton.OkCancel);
}
The following code i am writing in the Constructor() of the class , I just want to know two things
I want to exit the application when the user presses the "NO " button on the MessageBox
I was confused, should i use the application_launching() event or Should I code in OnNavigatedTo() ?
Proper code is required ! Thanks :-)
Upvotes: 1
Views: 449
Reputation: 5557
If you write your MessageBox in Constructor on OnNavigatedTo events, you will face the same issue. You have to handle it wisely in the page's Loaded
event handler.
Programmatically there is no preffered way to exit the app. Instead of deciding to exit the app, I suggest you show some static content and a "No network available, try later" text on the page.
Upvotes: 2