Creating network-aware synchronization modules

In a Microsoft SQL Server CE setup, you may want to initiate a sync automatically when a network connection is detected. You can do this quite easily by tapping into the WindowsMobile.Status namespace to be automatically notified whenever a change in the number of network connections occurs on the mobile device.

The SystemProperty.ConnectionsCount property increments whenever a GPRS/EDGE, Wi-fi, or any other connection is established. Using the SystemState class that you've learned in the last chapter, you can listen in on this property and be automatically notified once its value changes. You can achieve this with the following code snippet.

using Microsoft.WindowsMobile.Status;
SystemState _detector;
//Setup the event handler
public void StartDetector()
{
_detector = new
SystemState(SystemProperty.ConnectionsCount, true);
_detector.Changed += detector_Changed;
}
//The event handler will check if there is more than 1 //connection available. If there is, a sync is initiated
private void detector_Changed(object sender, ChangeEventArgsargs)
{ if (SystemState.ConnectionsCount>0)
{
//Run the sync here
PerformTheSync();
}
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.138.223