Пример #1
0
        private static async void Timer_Tick(ThreadPoolTimer timer)
        {
            await Task.Yield();
            try
            {
                NtpClient ntp = new NtpClient("au.pool.ntp.org");

                var accurateTime = await ntp.GetNetworkTimeAsync(TimeSpan.FromSeconds(10));

                utcOffset = DateTime.UtcNow.Subtract(accurateTime);
            }
            catch { }
        }
Пример #2
0
        public static async void StartNtpTimeService()
        {
            try
            {
                if (NtpInitalised) { return; }
                NtpInitalised = true;

                NtpClient ntp = new NtpClient("au.pool.ntp.org");

                //http://stackoverflow.com/questions/1193955/how-to-query-an-ntp-server-using-c
                var accurateTime = await ntp.GetNetworkTimeAsync(TimeSpan.FromSeconds(15));

                utcOffset = DateTime.UtcNow.Subtract(accurateTime);
            }
            catch { }

        //    ntpTimer = ThreadPoolTimer.CreatePeriodicTimer(Timer_Tick, TimeSpan.FromMinutes(5));
        }