Board index » off-topic » Performing an opperation once a minute

Performing an opperation once a minute


2004-02-07 07:22:24 PM
off-topic2
Hi
I need to make my program perform an action once every minute, one
opportunity would have been to use nested loops (assuming that they
could be done accurately enough) but because of the nature, i can't see
them treating the processor resources as precious, so is there an other
way i can achieve this effect?
Dan
 
 

Re:Performing an opperation once a minute

"Danny" < XXXX@XXXXX.COM >schreef in bericht
Quote
Hi

I need to make my program perform an action once every minute, one
opportunity would have been to use nested loops (assuming that they
could be done accurately enough) but because of the nature, i can't
see
them treating the processor resources as precious, so is there an
other
way i can achieve this effect?

Dan

Perhaps this is of any help.
With the program below you can create as many timers as you want, they
take up no resources whatsoever, but you have to check yourself whether
the timer flag has fallen or not. I use a similar method for starting a
synchronisation procedure every second, while the same program also has
to watch over the keyboard, mouse and RS232 port. The more often you
check the timers, the more accurate the timing will be, with a maximum
resolution of approximately 0.05 seconds, which is the system clock
readout. If you have lengthy procedures you should interrupt them now
and then for checking the timers.
If the starttime + duration>now the function checks true and this also
resets the starttime.
Program timer;
uses crt,dos;
function checktime(var starttime:longint;duration:longint):boolean;
var h, m, s, hund : Word;
var now:longint;
begin
GetTime(h,m,s,hund);
now:= longint(hund)+100*(longint(s)+60*(longint(m)+60*longint(h)));
if now < starttime then inc(now,8640000); {passed the 24 hour border}
if (now>= starttime+duration) then
begin
checktime:=true;
starttime:=now;
if (starttime>8640000) then dec(starttime,8640000);
end
else checktime:=false;
end;
const time1:longint=0;
time2:longint=0;
begin
repeat
if checktime(time1,50) then write('Hello ');
if checktime(time2,170) then writeln('World');
until keypressed;
while keypressed do readkey;
end.