using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Collections; using Microsoft.WindowsMobile.Status; namespace simple_snapi_ul { public partial class Form1 : Form { private Timer SyncTimer = null; public Form1() { InitializeComponent(); SetUpNotifications(); } private ArrayList stateList = new ArrayList(); public void SetUpNotifications() { // This tells which states to monitor SystemState s; // Monitor for ActiveSync Connection s = new SystemState(SystemProperty.CradlePresent); s.Changed += new ChangeEventHandler(ChangeOccurred); stateList.Add(s); // Monitor for GPRS Connection s = new SystemState(SystemProperty.PhoneGprsCoverage); s.Changed += new ChangeEventHandler(ChangeOccurred); stateList.Add(s); //Monitor for Network Connection (eg. WiFi) s = new SystemState(SystemProperty.ConnectionsNetworkCount); s.Changed += new ChangeEventHandler(ChangeOccurred); stateList.Add(s); UpdateConnectionState(); } public void ChangeOccurred(object sender, ChangeEventArgs args) { // If a change occurs SystemState state = (SystemState)sender; UpdateConnectionState(); } public void UpdateConnectionState() { // Set the check boxes based on the current state of the networks activesync.Checked = Convert.ToBoolean(SystemState.GetValue(SystemProperty.CradlePresent)); gprs.Checked = Convert.ToBoolean(SystemState.GetValue(SystemProperty.PhoneGprsCoverage)); wifi.Checked = Convert.ToBoolean(SystemState.GetValue(SystemProperty.ConnectionsNetworkCount)); } private void btnSync_Click(object sender, EventArgs e) { Sync(); } private void Sync() { // Sync MessageBox.Show("A synchornization would now be executed"); ////////////////////////////////////////////////////////// // // // Insert Sync Code Here // // // ////////////////////////////////////////////////////////// txtStatus.Text = "Synchronization complete."; } private void button2_Click(object sender, EventArgs e) { Application.Exit(); } public void SyncTimerEvent(object unused, EventArgs notused) { Sync(); } private void chkTimer_CheckStateChanged(object sender, EventArgs e) { this.SyncTimer = new Timer(); this.SyncTimer.Interval = 5000; this.SyncTimer.Enabled = false; this.SyncTimer.Tick += new EventHandler(SyncTimerEvent); if (chkTimer.Checked) this.SyncTimer.Enabled = true; else this.SyncTimer.Enabled = false; } } }