Solved

Pausing without using CPU power or blocking application

Posted on 2004-04-11
2
236 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
2 Comments
 
LVL 6

Accepted Solution

by:
rbohac earned 50 total points
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now