Intercettare il cambiamento di rete in Windows Phone 7.1
Nello script #39 abbiamo visto come la classe DeviceNetworkInformation introduca informazioni dettagliate per conoscere le caratteristiche della rete a cui il device è collegato. Tale classe dispone anche dell'evento NetworkAvailabilityChanged, che si scatena quando la disponibilità della rete cambia.
Il parametro NetworkNotificationEventArgs passato al gestore dell'evento dispone delle proprietà NetworkInterface e NotificationType con le quali possiamo accedere ad un ricco insieme di enumeratori che descrivono nel particolare lo stato corrente.
DeviceNetworkInformation.NetworkAvailabilityChanged += (object obj, NetworkNotificationEventArgs args) => { NetworkInterfaceInfo interfaceInfo = args.NetworkInterface; string data2 = string.Empty; data2 += String.Format("{0} InterfaceName: {1}", Environment.NewLine, interfaceInfo.InterfaceName); data2 += String.Format("{0} Description: {1}", Environment.NewLine, interfaceInfo.Description); data2 += String.Format("{0} Bandwidth: {1}", Environment.NewLine, interfaceInfo.Bandwidth); data2 += String.Format("{0} InterfaceState: {1}", Environment.NewLine, interfaceInfo.InterfaceState); //ConnectState data2 += String.Format("{0} InterfaceType: {1}", Environment.NewLine, interfaceInfo.InterfaceType); //NetworkInterfaceType data2 += String.Format("{0} InterfaceSubtype: {1}", Environment.NewLine, interfaceInfo.InterfaceSubtype); //NetworkInterfaceSubType data2 += String.Format("{0} Characteristics: {1}", Environment.NewLine, interfaceInfo.Characteristics); //NetworkCharacteristics data2 += String.Format("{0} NotificationType: {1}", Environment.NewLine, args.NotificationType); //NetworkNotificationType MessageBox.Show(data2); };
Questo evento può risultare molto utile per quelle applicazioni il cui funzionamento è strettamente vincolato alla presenza della rete dati.








