Solved

refreshing a form while it's busy

Posted on 2003-11-15
4
228 Views
Last Modified: 2010-04-05
I'm trying to make my program window stay painted even if another screen is activated and displayed in front of it.  This program runs a bunch of external programs.  I also have a duration to show how long it's been running.  My problem is that while I'm waiting for the process to complete, I am trying to make the program refresh the screen so that if I move a window over it, I can still go back to the screen and see the program status.  I don't feel all that confident in my understanding of the difference between update, refresh, and repaint, or what it means for an object to be invalid.  I have tried a bunch of combinations, but none of them work.  Here's what I have for the loop that I use to wait for the running process to complete.  Thanks in advance for your assistance.

repeat
  sleep( 2000 );
  lblTime.Caption := FormatDateTime('nn:ss',Time - StartTime);
  FrmMain.Refresh;
  GetExitCodeProcess(ProcessInfo.hProcess,Resultado);
  Result := Resultado;
until (Result <> STILL_ACTIVE) or Application.Terminated;
0
Comment
Question by:bnac
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
DaFox earned 200 total points
Comment Utility
Hi,

Application.ProcessMessages doesn't work? E.g. replace sleep(2000) with Application.ProcessMessages...

Markus
0
 
LVL 33

Expert Comment

by:Slick812
Comment Utility
hello bnac, , you might use a different code to wait for your other process to finish

if FileExists(ProcessInfo.lpFile) and ShellExecuteEx(@ProcessInfo) then
  begin
  while WaitForSingleObject(ProcessInfo.hProcess, 100) <> WAIT_OBJECT_0 do
    begin
    lblTime.Caption := FormatDateTime('nn:ss',Time - StartTime);
    //  if you have Application.ProcessMessages you will NOT need the Refresh
    Application.ProcessMessages;
    end;
  end else
  ShowMessage(SysErrorMessage(GetLastError));
0
 
LVL 3

Author Comment

by:bnac
Comment Utility
Markus,

I added Application.ProcessMessages, and dropped the sleep time to 250, and it's working exactly as I expected.  Taking out the sleep time caused the program to go from 0% CPU utilization to 90%.  Thanks for your amazingly quick response!

Matt
0
 
LVL 3

Author Comment

by:bnac
Comment Utility
Slick, Thanks for your reply.  I'm going to keep the wait loop that I have though, because I've used it in a few apps, and it works well.
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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

728 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

10 Experts available now in Live!

Get 1:1 Help Now