Forum > PDAs and Smartphones
how to use a timer,for some miliseconds
(1/1)
donnie:
Hello,
Does anyone knows how to use a timer to execute a procedure for some miliseconds?I mean that I want to wait for connecting a port to a PDA.If the port doesn't respond for spesific time I want to end and return false.For example if my procedure is waitcomrespond(); I want to do
--- Code: ---E:boolean;
while untilmytimerends do
begin
E := waitcomrespond;
end;
if mytimerends E=false
.....
--- End code ---
Thank you...
Zoran:
This should work (it's simple, without timer component):
--- Code: ---var
EndTime: TDateTime;
begin
...
EndTime := Now + EncodeTime(0, 0, 0, 500); // 0 hours, 0 minutes, 0 seconds, 500 miliseconds - you put what you want.
While Now < EndTime do
Application.ProcessMessages; // while this code is waiting, let the other application's code work.
// Here put the code which will execute after waiting time has passed.
...
end;
--- End code ---
felipemdc:
You can also use EpikTimer, precision timer:
http://wiki.lazarus.freepascal.org/EpikTimer
I've never tested it in Windows CE, but at most it should require minor modifications to work.
cokocool:
gracias Zoran
Jurassic Pork:
hello kokocool,
the zoran's code is not perfect because it uses too much the cpu if this code is in the main thread. You must add a sleep instruction in the loop to avoid this, like that :
--- Code: --- While Now < EndTime do
begin
Application.ProcessMessages; // while this code is waiting, let the other application's code work.
Sleep(10);// suspend the main thread for 10 ms between each check on Endtime
end;
--- End code ---
Friendly, J.P
Navigation
[0] Message Index