The error that you get "NtpException: Request timed out - no answer in 60000 ms" means that we did not receive response for the request of our client. Some of the time servers we encountered are sometimes not reliable enough. Simply said the unreliability can be solved by using a try catch block and retrying the method that throw error.
Actually, the static method Ntp.SynchronizeSystemClock
combines two things. First it connects to the NTP server and second it gets the time from the server and synchronizes the device time then.
I don't know what part fails in your case, to find out it would be good to use the non-static method (just create instance of Ntp and then call the SynchronizeSystemClock on it).
You could then retry the critical methods for instance like this:
// connects to the server. THe method retries it 3 times before giving up
Ntp ntp = ConnectToNtpRetryOnTimeoutFailure("pool.ntp.org");
// receives actual time from the server
// this method can also timeout in case the server does not respond within the ntp.Timeout range (in miliseconds)
// you might want to retry the SynchronizeSystem clock operation in the same fashion if it causes problems:
ntp.SynchronizeSystemClock();
private Ntp ConnectToNtpRetryOnTimeoutFailure(string server)
{
int cnt_max = 3;
Ntp ntp = null;
for (int i = 0; i < cnt_max; i++)
{
try
{
ntp = new Ntp(server);
break;
}
catch (NtpException ex)
{
// NtpException: Request timed out -no answer in 60000 ms
if (!ex.Message.StartsWith("Request timed out"))
throw;
if (i + 1 == cnt_max)
throw new ApplicationException(string.Format("Unable to connect to NTP server (retried {0} times). Error {1}", cnt_max, ex.ToString()));
continue;
}
}
return ntp;
}
Please give the code above a try and let me know whether retrying the operation helps.