[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 252
  • Last Modified:

Pausing without using CPU power or blocking application

Hi,

last question, then mi application is finished! ;-)

Is there a possibility to pause my application without using a lot of CPU power or blocking it from taking any new commands?

When I use "sleep()", my application is blocked and doesn't take any new commands.

And with:

procedure TForm1.pause(time1: longword);
var time2 : longword;
begin
      time2 := GetTickCount;
      repeat
                Application.ProcessMessages;
      until (GetTickCount - time2 > time1);
end;

CPU usage raises to 100% immediately. This is not very usefull, because I have a thread which is waiting for CPU usage to fall below a specific percentage...

Any other ideas? thanks
0
Bohne
Asked:
Bohne
1 Solution
 
rbohacCommented:
you are on the right track. Combine Application.ProcessMessages with a 1ms sleep

procedure pause(Seconds:Cardinal);
var StartTime:Cardinal;
begin
     StartTime := GetTickCount;
     Seconds   := Seconds * 1000;
     repeat
               Application.ProcessMessages;
               sleep(1);
     until (GetTickCount > (StartTime + Seconds));
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  Pause(5);
  ShowMessage('Hello');
end;
0
 
mokuleCommented:
I don't know the nature of Your pause but maybe the use of TTimer would be good solution.

It is also important what time periods do You need.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now