Example #1
0
        private static void SyncLocalTimeOffset()
        {
            double localOffset = 0;

            while (true)
            {
                try
                {
                    localOffset = GetLocalClockOffset();

                    _RWLocalOffsetLock.EnterWriteLock();

                    try
                    {
                        LocalOffsetSeconds = localOffset;
                    }
                    finally
                    {
                        _RWLocalOffsetLock.ExitWriteLock();
                    }
                }
                catch (System.Exception)
                {
                }

                try
                {
                    Thread.Sleep(SNTPSettings.GetConfigOrDefault().PoolInterval);
                }
                catch (System.Exception)
                {
                    Thread.Sleep(60000);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Creates a new instance of SNTPClient.
        /// </summary>
        public SNTPClient()
        {
            this.InitializeComponent();

            this.Initialize();
            this.ThreadStart         = new WorkerThreadStartDelegate(WorkerThreadStart);
            this.OperationCompleted  = new SendOrPostCallback(AsyncOperationCompleted);
            this.Timeout             = SNTPSettings.GetConfigOrDefault().Timeout;
            this.VersionNumber       = DefaultVersionNumber;
            this.UpdateLocalDateTime = false;
        }
Example #3
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public static double GetLocalClockOffset()
 {
     return(GetLocalClockOffset(SNTPSettings.GetConfigOrDefault().Timeout));
 }
Example #4
0
 /// <summary>
 /// Gets the real local date and time using the specified server and a total timeout of 1 second.
 /// If there is an error or exception, DateTime.MinValue is returned.
 /// </summary>
 /// <param name="remoteSNTPServer">The server to use.</param>
 /// <returns>The real local date and time.</returns>
 public static DateTime GetNow(RemoteSNTPServer remoteSNTPServer)
 {
     return(GetNow(remoteSNTPServer, SNTPSettings.GetConfigOrDefault().Timeout));
 }
Example #5
0
 /// <summary>
 /// Gets the real local date and time using the default server and a total timeout of 1 second.
 /// If there is an error or exception, DateTime.MinValue is returned.
 /// </summary>
 /// <returns>The real local date and time.</returns>
 public static DateTime GetNow()
 {
     return(GetNow(SNTPSettings.GetSNTPServer(), SNTPSettings.GetConfigOrDefault().Timeout));
 }