how to check InternetConnection in wp7?
Asked Answered
G

3

9

i want to check internet connection in my application.but, its not displaying properly.

i am using this code for internet connection:

 NetworkInterface.GetIsNetworkAvailable();

in this code always return true value.if net available or not available return true only.

if anyone know tell me idea to do this.

thanks.

Garnetgarnett answered 1/12, 2011 at 12:11 Comment(2)
possible duplicate of How to check connection services when using webservices?Rookery
It proposes the same answer. So tired of false duplicates.Eddington
S
16

Check NetworkInterfaceType. If Internet is available then It should be other than None

 return (Microsoft.Phone.Net.NetworkInformation.NetworkInterface.NetworkInterfaceType != 
 Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.None);
Surfacetosurface answered 1/12, 2011 at 12:31 Comment(3)
NetworkInterface.GetIsNetworkAvailable();NetworkInterface.Equal(); NetworkInterface.RefenceEqual(); showing this 3 option only. NetworkInterface.NetworkInterfaceType this option not avialble check it.Garnetgarnett
It's in Microsoft.Phone.Net.NetworkInformation namespace. You are probably using System.Net.NetworkInformation and looking thereTowne
Any idea why calling this from WP8 emulator with no network makes VS and the emulator not respond for 10-15 seconds?Supportable
L
6

In the Windows Phone Emulator it's correct that NetworkInterface.GetIsNetworkAvailable() will always return true. Even if your PC has no internet connection, the emulator counts the local/internal connection to your PC.

The return value will be false if you test your application on a real device and switch it e.g. in flight-mode.

Luncheonette answered 1/12, 2011 at 16:3 Comment(0)
T
3

Yes NetworkInterface.GetIsNetworkAvailable() will always return true on windows phone emulator you can try below code to detect network availability.

using Microsoft.Phone.Net.NetworkInformation;    
    if (DeviceNetworkInformation.IsNetworkAvailable)
    {
    MessageBox.Show("network available") ;              
    }
    else
    {
    MessageBox.Show("No network.") ;   
    }
Televisor answered 9/12, 2013 at 13:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.