Pregunta

I am developing a Windows Phone 8 App with C# and my app needs to realize automatically when the network availability has changed.

So, when the Windows Phone is suddenly connected to the internet I need to take some actions, but I really do not know how to check this. I don't want to set a Timer, running constantly in a Thread for checking this every couple of seconds.

Is there any Method (similar to the OnNavigatedTo method), that is launched automatically, when the phone connects to the internet?

If so, what is the best and most efficient way to implement this?

Thank you for all tips and your help in advance!

¿Fue útil?

Solución 2

All what you need is NetworkAvailabilityChanged event. You can find all available information in the DeviceNetworkInformation Class.

Otros consejos

use this nameSpace

using Microsoft.Phone.Net.NetworkInformation;

 if (NetworkInterface.GetIsNetworkAvailable() == true)
   {
     //Do something
   }
   else
   {
      //Do Something
   }

Use the Hollywood principle instead of polling:

NetworkInformation.NetworkStatusChanged

You can check network availability in .Net Framework 2.0 using

if(System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
{
  //Do your stuffs when network available

}
else
{
  //Do stuffs when network not available

}

It will return true or false.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top