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); } } }
/// <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; }
/// <summary> /// /// </summary> /// <returns></returns> public static double GetLocalClockOffset() { return(GetLocalClockOffset(SNTPSettings.GetConfigOrDefault().Timeout)); }
/// <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)); }
/// <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)); }