//-------------------------------------------------------------------------------------------------// public bool GetTimeOfDay(string serverUrl, ref DateTime dateTime) { const string STRLOG_MethodName = "GetTimeOfDay"; Logfile.WriteCalled(STRLOG_ClassName, STRLOG_MethodName); this.lastError = null; bool success = false; // // Need to run for the full execution time, so get the time now // DateTime dateTimeStart = DateTime.Now; try { // // Get the time from the specified NTP server // NTPClient ntpClient = new NTPClient(serverUrl); if (ntpClient.Connect(this.ntpTimeout, false) == false) { throw new Exception(STRERR_FailedToRespond); } dateTime = ntpClient.TransmitTimestamp; success = true; } catch (Exception ex) { dateTime = DateTime.MinValue; this.lastError = ex.Message; Logfile.WriteError(ex.Message); } // // Delay for the full execution time // DateTime dateTimeEnd = dateTimeStart + new TimeSpan(0, 0, this.ntpTimeout); while (DateTime.Now < dateTimeEnd) { Trace.Write("N"); Thread.Sleep(1000); } Trace.WriteLine(""); string logMessage = STRLOG_Success + success.ToString() + Logfile.STRLOG_Spacer + STRLOG_TimeOfDay + dateTime.ToString(); Logfile.WriteCompleted(STRLOG_ClassName, STRLOG_MethodName, logMessage); return(success); }
//-------------------------------------------------------------------------------------------------// public bool GetTimeOfDay(string serverUrl, ref DateTime dateTime) { const string STRLOG_MethodName = "GetTimeOfDay"; Logfile.WriteCalled(STRLOG_ClassName, STRLOG_MethodName); this.lastError = null; bool success = false; // // Need to run for the full execution time, so get the time now // DateTime dateTimeStart = DateTime.Now; try { // // Get the time from the specified NTP server // NTPClient ntpClient = new NTPClient(serverUrl); if (ntpClient.Connect(this.ntpTimeout, false) == false) { throw new Exception(STRERR_FailedToRespond); } dateTime = ntpClient.TransmitTimestamp; success = true; } catch (Exception ex) { dateTime = DateTime.MinValue; this.lastError = ex.Message; Logfile.WriteError(ex.Message); } // // Delay for the full execution time // DateTime dateTimeEnd = dateTimeStart + new TimeSpan(0, 0, this.ntpTimeout); while (DateTime.Now < dateTimeEnd) { Trace.Write("N"); Thread.Sleep(1000); } Trace.WriteLine(""); string logMessage = STRLOG_Success + success.ToString() + Logfile.STRLOG_Spacer + STRLOG_TimeOfDay + dateTime.ToString(); Logfile.WriteCompleted(STRLOG_ClassName, STRLOG_MethodName, logMessage); return success; }