Checking for Internet Connectivity in Windows 8 C#/winrt

To prevent winrt app from crashing while doing web method due to the lack of Internet Connectivity, always use the below code to check for Internet Connectivity.
Declaring the method in App.cs would ease the usage.
Ideally the app should inform the user to check its internet connection before trying again.


public static bool IsConnectedToInternet()
{
            ConnectionProfile connectionProfile = NetworkInformation.GetInternetConnectionProfile();
            return (connectionProfile != null && connectionProfile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess);
}

Advertisements
This entry was posted in winrt and tagged , , , , . Bookmark the permalink.

3 Responses to Checking for Internet Connectivity in Windows 8 C#/winrt

  1. foods says:

    I do not know if it’s just me or if everybody else experiencing problems with your site.
    It appears as if some of the written text within your content are running
    off the screen. Can someone else please comment and let me know if this is
    happening to them too? This could be a problem with my internet
    browser because I’ve had this happen previously.
    Kudos

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s