예제 #1
0
 /// <summary>
 /// Gets the real local date and time using the default server and the specified timeout.
 /// If there is an error or exception, DateTime.MinValue is returned.
 /// </summary>
 /// <param name="remoteSNTPServer">The server to use.</param>
 /// <param name="timeout">The timeout in milliseconds used for sending and receiving.</param>
 /// <returns>The real local date and time.</returns>
 public static DateTime GetNow(RemoteSNTPServer remoteSNTPServer, int timeout)
 {
     SNTPClient sntpClient = new SNTPClient();
     sntpClient.UpdateLocalDateTime = false;
     sntpClient.RemoteSNTPServer = remoteSNTPServer;
     sntpClient.Timeout = timeout;
     QueryServerCompletedEventArgs args = sntpClient.QueryServer();
     if (args.Succeeded)
         return DateTime.Now.AddSeconds(args.Data.LocalClockOffset);
     else
         return DateTime.MinValue;
 }
예제 #2
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, 500);
 }