Solved

Pausing without using CPU power or blocking application

Posted on 2004-04-11
2
241 Views
Last Modified: 2010-04-04
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
Comment
Question by:Bohne
[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
2 Comments
 
LVL 6

Accepted Solution

by:
rbohac earned 50 total points
ID: 10800596
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
 
LVL 17

Expert Comment

by:mokule
ID: 10801135
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

687 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