Solved

Pausing without using CPU power or blocking application

Posted on 2004-04-11
2
239 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SUM 2 INTEGER ARRAYS INTO 1 10 111
JAudiorecorder record freezing the app 29 83
Delphi problems to abort a printjob 9 34
Delphi Seattle StructureView color 1 21
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…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

733 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