Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2005 Feb : Preventing other things to happen while setting the time

www.cryer.info
Managed Newsgroup Archive

Preventing other things to happen while setting the time

Subject:Preventing other things to happen while setting the time
Posted by:"David Henningsson" (n..@nil.se)
Date:16 Feb 2005 08:34:57

Say that I am a client that wants to synchronize my time with a
server's time. So I send a time request and receive a time
response from the server. If this takes too long time (say, more
than a second), the time is not set because it will be
inaccurate. Otherwise, I call "SetSystemTime".

The code would look something like:

A := GetTickCount;
SendTimeRequest;
NewTime := WaitForTimeReply;
if GetTickCount-A < 1000 then
  SetSystemTime(NewTime);

However, there is a small chance that between the GetTickCount
and the SetSystemTime calls, Windows will decide that it's time to
do a disk cache flush, refresh a web page, or whatever. And as a result, the
computer's clock will be wrong.

Is there a "bulletproof" way of avoiding this behavior, or
another way to design, etc?

// David

Replies:

www.cryer.info
Managed Newsgroup Archive