[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How To Increase The Timer Interval After The Timer Is Already Started?

Posted on 2010-11-09
4
Medium Priority
?
733 Views
Last Modified: 2012-05-10
I have a data aquisition app that has a procedure that is continuously called by a timer every 3 seconds. Depending on the procedures execution, additional time is sometimes required for the procedure to complete (because of external variables) before its time for the timer to fire and execute it again. I could solve the problem by resyncronizing the timer as the procedure time requirement changes.

Is there a way to extend, or change, the timer interval once the timer's been enabled?
0
Comment
Question by:jsmitter
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 13

Accepted Solution

by:
rfwoolf earned 1000 total points
ID: 34098366
What you should be doing is, on the timer's onTimer event, you disable the timer, and then in a try...finally statement you re-enable it again, e.g.

Timer1.Enabled := false;
try
  //Do your processing
finally
  Timer1.Enabled := true;
end;
0
 
LVL 14

Expert Comment

by:systan
ID: 34099019
you could use the; gettickcount() function
eq.,
var
tick: cardinal;
...
begin
tick := gettickcount();
..
..
tick := gettickcount - tick;
...
if tick>=3000 then
tick := tick - 3000;
...
showmessage(inttostr(tick));
...
0
 
LVL 25

Expert Comment

by:epasquier
ID: 34101144
rfwoolf is almost right. The solution is to stop and restart the timer after setting a different interval. But not on the timer onTimer event, right when your application detects a condition that needs extra time for your process.
I often use a procedure like this one to reset timers. Most of the time, I don't even change the interval, because I just need the same time allowed but from now on. Ex : when recieving data from a COM port, a time-out is usually not from the start of the message, but from the last character received.
procedure ResetTimer(aTimer:TTimer;RemainingTime:Cardinal=0);
begin
 With aTimer do
  begin
   enabled:=False;
   if RemainingTime>0 Then Interval:=RemainingTime;
   enabled:=True;
  end;
end;

Open in new window

0
 
LVL 32

Assisted Solution

by:Ephraim Wangoya
Ephraim Wangoya earned 1000 total points
ID: 34117513
You dont need to change the timer interval at all. Using the OnTimer event is a good solution since you have no way of knowing how long the procedure your are executing will take. Disable the timer until you are done with the process as rtwolf points out.

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Timer1.Enabled := False;
  try
    ProcessData;
  finally
    Timer1.Enabled := True;
  end;
end;

The down side of this is that, while the procedure is running, your application has to wait for it to finish and you may be receciving more data to process at the same time.
An even better solution would be to fire a thread and let it handle the incoming data. This way your application is always responsive and you ont have to worry about timers and how long the procedure will take.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question