Only allow full synchronisations when a WindowsMobile device is cradled

When developing a Windows Mobile based application, you’re often presented with the “I want everything synchronised between my device and my PC” scenario.

While yes, it’d be great to have everything synchronised when you’re on the go (via GPRS, etc), and having little changes filtered through to the device.

The little changes is fine, but what about doing a full synchronisation? Surely, you wouldn’t want users to do a full sync whilst out on the road with data being charged per kilobyte (at a high rate)?

I’m not too sure how the data rates (for GPRS) are overseas, but over here depending upon your telco, it does get quite pricey after you go beyond your alloted monthly data allowance.

One way of disabling a full synchronisation whilst on GPRS is to use the SystemState.Changed event to detect when the device is cradled.

Here’s an example (using Windows Mobile 5.0’s managed API and C#):

public class Form1 : Form
Microsoft.WindowsMobile.Status.SystemState systemState;
public Form1()
systemState = new Microsoft.WindowsMobile.Status.SystemState(Microsoft.WindowsMobile.Status.SystemProperty.CradlePresent);
systemState.Changed += new Microsoft.WindowsMobile.Status.ChangeEventHandler(systemState_Changed);

protected void systemState_Changed(object sender, Microsoft.WindowsMobile.Status.ChangeEventArgs args)
// Show whether the cradle is present
MessageBox.Show("Is the cradle present? " + Microsoft.WindowsMobile.Status.SystemState.CradlePresent.ToString());

The above is just some sample code that you can modify to meet your requirements.

You could use the boolean value returned by SystemState.CradlePresent to toggle your full synchronisation option.

You should also check out the State and Notification Broker sample that comes with the Windows Mobile 5.0 SDK.

Comments are closed.