Forum Discussion
Hi William,
Could you please clarify your request?- williamleeContributorHi
I want apply 2 timer event in one code since i already use one timer event in the code, I plan to add another one, can I do this, does this cause any conflict of the code?
thanks - AlexKarasChampion Level 3Hi William,
I think (but did not verified this) that technically it might be possible to create more than one timer, but as timers are not synchronized with anything (except with rough time intervals as Windows is not real-time OS) you will have to perform some extra actions to determine what timer was triggered. Why not to put all code into one timer? - williamleeContributorHi
Yes, you are right, I now trying to do this. But somehow I faced one duffculty. I have two method in one timer. The timer trigger time is about 1500ms. One question is how timer operate? What I mean is:
when
the code start run, when it hit 1500ms, it go to serve the timer rountine method. When it inside the timer routine method, does the timer still count(1500->1501->....) or it already stop for a while until it finish it tasks inside the timer. Before it go out, the timer reset back to zero and continue to recount?
If the timers stop when it stop inside the timer rountine and reset to zero before it go out, why I can;t see this kind of scenario? Does it required any setting to do this?
thanks - AlexKarasChampion Level 3Hi William,
I think that Support will provide you with exact answer, but my educated guess is that timer count is not stopped (like it is for regular Windows timers).
When I implemented a functionality like this I used a global flag variable to signal whether the timer code is running or not. - Hi William,
As it is stated in the Timer Object help topic, it is possible to add multiple Timer objects to the Timers collection.
Alexei is right - the timer is not stopped. That's why it's not a very good idea to invoke routines which take long to execute by a timer. - williamleeContributorHI Allen,
thanks for your clarification.
Hi Alexei,
how to use used a global flag variable to signal whether the timer code is running or not? Can you show me with a sample code?
thanks - AlexKarasChampion Level 3Hi William,
Some untested DelphiScript-like pseudo-code (just because it supports try/finally) off top of my head:
var boolInHandler
procedure OnStartTest(); // can be event handler for the OnStartTest event - see help for more details
begin
boolInHandler := false;
...
end;
procedure TimerHandler();
begin
if (boolInHandler) then
exit;
boolInHandler := true;
try
...
finally
boolInHandler := false;
end;
end;
Related Content
- 7 years ago
- 14 years ago
Recent Discussions
- 3 days ago
- 3 days ago
- 6 days ago