[EN] Listen network status changes on W8.1/WP8.1

There is not much information about how to manage network status changes on Windows phone 8.1 because it is relatively new. The essential thing is remember that Windows 8.1 and Windows Phone are in a melting process and the solutions for Windows 8 are valid for the phone apps.

And this is one of the situations, if you try to follow the solutions given for the Windows Phone version 8 you will find that the answers don´t fix the problem and the device don´t react to the event. But keep calm and continue developing, breathe a little and see the connection management is different in Windows 8.1 and therefore can use the namespace Windows.Networking.Connectivity instead of Microsoft.Phone.Net.NetworkInformation and manage the connection of Windows 8.1 and Windows Phone 8.1 apps.

In my case I wanted to create an inheritable class to other classes then you’ll use throughout the development to bring the event to notify them of a change to the connection so you can react to it, moving or making persistent app data.

The sample is really easy, in the constructor of the class we will add a new handler to NetworkStatusChanged of NetworkInformation.

In this way when the class inherits will be listening to initialize the event of change of connection status. We also added a method that tells us whether you are online or not and finally our connection handle. After event throws we will just ask if the device is connected and act accordingly.

This is not a complex solution and reviewing how the method IsConnected is evaluated can learn many things about how to manage other events how, for example, whether the connection is high or low, because perhaps under very low levels of connection compensate not even try to send or request information.