Board index » delphi » TTimer - OnTimer event

TTimer - OnTimer event

I've a function that can take some time, and it's to run at a regular
interval 1 sek.

So I set my timerinterval to 1 sek. Now The question. What happens if my
function takes longer timer than the 1 sek.

Or is there a better way to do this

Regards

Peter Svejgaard

 

Re:TTimer - OnTimer event


At the start of the OnTimer event, turn the timer off. Turn it back on
at the end of the event.

Wayne

Quote
Peter Svejgaard wrote:

> I've a function that can take some time, and it's to run at a regular
> interval 1 sek.

> So I set my timerinterval to 1 sek. Now The question. What happens if my
> function takes longer timer than the 1 sek.

> Or is there a better way to do this

> Regards

> Peter Svejgaard

Re:TTimer - OnTimer event


Quote
In article <7j8e7o$n5...@forums.borland.com>, Peter Svejgaard wrote:
> I've a function that can take some time, and it's to run at a regular
> interval 1 sek.

> So I set my timerinterval to 1 sek. Now The question. What happens if my
> function takes longer timer than the 1 sek.

> Or is there a better way to do this

I define a global boolean variable called InTimer, at the start of the
timer I check it and exit if true, then I set it, do the stuff then unset
it at the end.  The small code fragment below shows how I do this

begin
    if InTimer then
        exit ;
    InTimer := true
    try
        //code
    finally
        InTimer := false ;
    end;
end;

--
 The Taz!

Re:TTimer - OnTimer event


Quote
In article <7j8e7o$n5...@forums.borland.com>, Peter Svejgaard wrote:
> So I set my timerinterval to 1 sek. Now The question. What happens if my
> function takes longer timer than the 1 sek.

Nothing bad, unless you call Application.ProcessMessages in the timer
event. The way Windows handles timers makes sure that timer messages do
not accumulate in the message queue. But your scenario will not leave much
CPU time for other things in your app so i would suggest you follow Waynes
advice to get at least a 1 sek breathing space before the next timer
event.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Re:TTimer - OnTimer event


Thank you Peter, I have asked a related question at twice in this group,
never got an answer, but with you response about the TTimer stuff here,
I now know for sure that the VCL does allow for Event re-entry if
Application.ProcessMessages is called from within.

This moves me on to ask if there are any VCL procedures/functions etc.
that perform such a call internally, or can I rely on them never ever to
do so.

      Steve Bliss

Other Threads