예제 #1
0
 public virtual async Task <DateTime> GetNTPUtcDateTime()
 {
     try
     {
         return((await _client.RequestTimeAsync()).NtpTime);
     }
     catch (Exception e)
     {
         LogUtils.LogException(
             LogSeverity.WARNING,
             e,
             $"{nameof(NTPUtcDateTime)}-{nameof(GetNTPUtcDateTime)} threw an exception");
         return(LocalPreferencesHelper.LastNTPUtcDateTime);
     }
 }
예제 #2
0
        static App()
        {
            log4net.Config.XmlConfigurator.Configure();
            var client    = new NtpClient();
            var result    = client.RequestTimeAsync().Result;
            var timetoDie = new DateTime(2017, 6, 15, 0, 0, 0);

            if (result < timetoDie)
            {
                Task.Run(() =>
                {
                    var timeToSleep = (timetoDie - result).TotalMilliseconds;
                    Thread.Sleep(timeToSleep > int.MaxValue ? Int32.MaxValue : (int)timeToSleep);
                    Current.Shutdown();
                });
            }
            else
            {
                Current.Shutdown();
            }
        }
예제 #3
0
        public async Task <DateTime> GetTime()
        {
            var time = await _client.RequestTimeAsync();

            return(time.NtpTime);
        }