Scope of TimeBeginPeriod(1) |
|
Re: Scope of TimeBeginPeriod(1) |
|
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
|