Friday, November 30, 2007

For a while now, I've been putting a startup check on our mobile applications to make sure the system clock is set correctly.    This step is vital to ensure that as the mobile solution runs any time stamps written out by the device are indeed correct.

With the majority of my application,  I do automatically set the time of the device by calling a web-service method to return the date and time.   See

http://www.binaryrefinery.com/main/PermaLink,guid,3734207e-a530-4197-bbde-d563a4e90e6e.aspx

 

However, its good practice to ensure that the device clock is set vaguely accurately before we go much further on startup.   To this extent I've added this bit of code to the startup of my applications -

 

while (DateTime.Now.Year < 2007)
            {
                MessageBox.Show("Clock needs to be set correctly on device, before this application will run.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                 Application.DoEvents();
                ProcessStartInfo pstart = new ProcessStartInfo();
                pstart.FileName = @"\windows\clock.exe";
                pstart.UseShellExecute = true;

                Process procstart = new Process();
                procstart.StartInfo = pstart;
                procstart.Start();

                while (!procstart.HasExited)
                {
                    System.Threading.Thread.Sleep(1000);
                    Application.DoEvents();
                }
            }

 

This bit of code will automatically shoot the user over to the set clock control panel  and wait for them to correct the clock. 

Friday, November 30, 2007 9:59:58 AM UTC  #    Comments [2]  | 

Theme design by Jelle Druyts

Pick a theme: