Beispiel #1
0
 void _ntpClient_TimeReceived(object sender, NtpClient.TimeReceivedEventArgs e)
 {
     this.Dispatcher.BeginInvoke(() =>
     {
         txtCurrentTime.Text = e.CurrentTime.ToLongTimeString();
         txtSystemTime.Text  = DateTime.Now.ToUniversalTime().ToLongTimeString();
     });
 }
Beispiel #2
0
        void ntpClient_TimeReceived(object _, NtpClient.TimeReceivedEventArgs e)
        {
            timeoutAction.Dispose();

            Dispatcher.BeginInvoke(() =>
            {
                Action nextAction = () =>
                {
                    NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
                    NavigationService.RemoveBackEntry();
                };

                if (e != null)
                {
                    TimeSpan ts        = (DateTime.UtcNow - e.CurrentTime);
                    App.TimeDifference = (long)ts.TotalMilliseconds;
                    IsolatedStorageSettings.ApplicationSettings["TimeDifference"] = App.TimeDifference;
                    IsolatedStorageSettings.ApplicationSettings.Save();

                    differenceTextBlock.Text = App.TimeDifference.ToString("d");
                    txtCurrentTime.Text      = e.CurrentTime.ToLongTimeString();
                    txtSystemTime.Text       = DateTime.Now.ToUniversalTime().ToLongTimeString();
                }
                else if (IsolatedStorageSettings.ApplicationSettings.Contains("TimeDifference"))
                {
                    differenceTextBlock.Text = txtCurrentTime.Text = txtSystemTime.Text
                                                                         = "Getting time failed. Use stored Value.";
                    App.TimeDifference = Convert.ToInt64(IsolatedStorageSettings.ApplicationSettings["TimeDifference"]);
                }
                else
                {
                    differenceTextBlock.Text = txtCurrentTime.Text = txtSystemTime.Text = "Getting time failed. Try later.";

                    nextAction = () => App.Current.Terminate();
                }
                Scheduler.Dispatcher.Schedule(nextAction, TimeSpan.FromSeconds(1));
            });
        }