Mega Search
23.2 Million


Sign Up

Make a donation  
Scope of TimeBeginPeriod(1)  
News Group: borland.public.delphi.nativeapi.win32

I am investigating improving the accuracy of a TEvent.WaitFor(APeriod) by
using a MMSystem.TimeBeginPeriod(1) call.

I have seen differing recommendations about calling TimeBeginPeriod(1):-

a) some say the calls should be minimized and can be made once in
application.OnCreate matched by a TimeEndPeriod(1) in application.OnDestroy
due to the effect of TimeBeginPeriod(1) being per application/process

b) others say the each time sensitive call should be enclosed in a try
finally

TimeBeginPeriod(1);
try
 AnEvent,WaitFor(APeriod)
finally
TimeEndPeriod(1);
end;

As the TimeBeginPeriod(1) could be invalidated by a call to
TimeBeginPeriod(xx) by another application.

Is either of the above correct or is the situation not this simple

Thanks


David



Vote for best question.
Score: 0  # Vote:  0
Date Posted: 17-Dec-2007, at 4:01 PM EST
From: David
 
Re: Scope of TimeBeginPeriod(1)  
News Group: borland.public.delphi.nativeapi.win32
David wrote:
> I am investigating improving the accuracy of a TEvent.WaitFor(APeriod) by
> using a MMSystem.TimeBeginPeriod(1) call.
> 
> I have seen differing recommendations about calling TimeBeginPeriod(1):-
> 
> a) some say the calls should be minimized and can be made once in
> application.OnCreate matched by a TimeEndPeriod(1) in application.OnDestroy
> due to the effect of TimeBeginPeriod(1) being per application/process

That's the opposite of everything recommended by the documentation. It 
says to call those functions "immediately before using timer services" 
and "immediately after you are finished using the timer services." 
Furthermore, it says the function "affects a global Windows setting."

> b) others say the each time sensitive call should be enclosed in a try
> finally
> 
> TimeBeginPeriod(1);
> try
>  AnEvent,WaitFor(APeriod)
> finally
> TimeEndPeriod(1);
> end;
> 
> As the TimeBeginPeriod(1) could be invalidated by a call to
> TimeBeginPeriod(xx) by another application.

The documentation says otherwise. "Windows uses the lowest value (that 
is, highest resolution) requested by any process."

> Is either of the above correct or is the situation not this simple

I have no idea. But unless you have reason to doubt it (i.e., you tests 
tell you differently), I recommend you trust the documentation.

-- 
Rob

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 17-Dec-2007, at 10:06 PM EST
From: Rob Kennedy