/// <summary> /// Synchronize time with echo /// </summary> public static void SynchronizeTime() { DateTime dtntp = new DateTime(); try { dtntp = TimeHandler.GetNetworkTime(); SYSTEMTIME st = new SYSTEMTIME(); st.wYear = Convert.ToInt16(dtntp.Year); st.wMonth = Convert.ToInt16(dtntp.Month); st.wDay = Convert.ToInt16(dtntp.Day); st.wHour = Convert.ToInt16(dtntp.Hour); st.wMinute = Convert.ToInt16(dtntp.Minute); st.wSecond = Convert.ToInt16(dtntp.Second); SetSystemTime(ref st); System.Windows.Forms.MessageBox.Show("Time has been synchronized!", "Success!", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); } catch (System.Net.Sockets.SocketException) { System.Windows.Forms.MessageBox.Show("Cannot connect to the local time server!", "Failed", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } }
/// <summary> /// Synchronize time silently /// </summary> public static void SilentSynchronizeTime() { DateTime dtntp = new DateTime(); try { dtntp = TimeHandler.GetNetworkTime(); SYSTEMTIME st = new SYSTEMTIME(); st.wYear = Convert.ToInt16(dtntp.Year); st.wMonth = Convert.ToInt16(dtntp.Month); st.wDay = Convert.ToInt16(dtntp.Day); st.wHour = Convert.ToInt16(dtntp.Hour); st.wMinute = Convert.ToInt16(dtntp.Minute); st.wSecond = Convert.ToInt16(dtntp.Second); SetSystemTime(ref st); } catch (System.Net.Sockets.SocketException) { // Do nothing } }