NetworkInterface.NetworkInterfaceType Property
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Gets the type of the network that is servicing Internet requests.
Assembly: Microsoft.Phone (in Microsoft.Phone.dll)
Property Value
Type: Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceTypeReturns NetworkInterfaceType.
private event EventHandler NetworkInterfaceTypeChanged;
private bool _networkTypeLoaded;
private NetworkInterfaceType _currentNetworkType;
public void PlayVideo(string videoId)
{
if (_networkTypeLoaded == false)
{
// The network type has not yet been determined, so
// show a loading screen and register for an event
// when the network type is known.
ShowLoadingScreen();
NetworkInterfaceTypeChanged +=
delegate
{
DismissLoadingScreen();
PlayVideo(videoId);
};
CheckCurrentNetworkType();
return;
}
switch(_currentNetworkType)
{
// If the device is connected to a cellular network,
// then play a low-resolution video.
case NetworkInterfaceType.MobileBroadbandCdma:
case NetworkInterfaceType.MobileBroadbandGsm:
PlayLowResVideo(videoId);
break;
// If the device is connected by Wi-Fi or connected to the desktop,
// then play higher-resolution video.
case NetworkInterfaceType.Wireless80211:
case NetworkInterfaceType.Ethernet:
PlayHighResVideo(videoId);
break;
// If no network connection is available,
// then display an error message.
case NetworkInterfaceType.None:
default:
DisplayNetworkUnavailableErrorMessage();
break;
}
}
private void CheckCurrentNetworkType()
{
// Checking the network type is not instantaneous,
// so we recommend that you always do it on a background thread.
ThreadPool.QueueUserWorkItem((o) =>
{
_currentNetworkType = Microsoft.Phone.Net.NetworkInformation.NetworkInterface.NetworkInterfaceType;
_networkTypeLoaded = true;
if (NetworkInterfaceTypeChanged != null)
{
NetworkInterfaceTypeChanged(this, EventArgs.Empty);
}
});
}
Show: