Solved

Blocking on WinExec in Delphi 1.0

Posted on 1997-10-29
6
1,064 Views
Last Modified: 2012-05-04
Is there a way to spawn a process in Delphi 1.0 and wait for it to run to completion?  WinExec() continues without waiting for the process to complete.
0
Comment
Question by:mozack
  • 3
  • 2
6 Comments
 

Accepted Solution

by:
98113772 earned 100 total points
ID: 1349131
Hi,

Try this one:

Function WinExecAndWait(Path : string; Visibility : word) : word;
var
  InstanceID : THandle;
  PathLen : integer;
begin
  { inplace conversion of a String to a PChar }
  PathLen := Length(Path);
  Move(Path[1],Path[0],PathLen);
  Path[PathLen] := #0;
  { Try to run the application }
  InstanceID := WinExec(@Path,Visibility);
  if InstanceID < 32 then { a value less than 32 indicates an Exec error }
     WinExecAndWait := InstanceID
  else
  begin
    Repeat
      Application.ProcessMessages;
    until Application.Terminated or (GetModuleUsage(InstanceID) = 0);
    WinExecAndWait := 32;
  end;
end;


<--- Cut --->

Greatings from Denmark
Claus Ziegler
0
 

Author Comment

by:mozack
ID: 1349132
No. ProcessMessages gives the control back to windows. The code
is fine.
0
 

Expert Comment

by:krisz
ID: 1349133
Hi,

No draining of the CPU is done. My answer is right. the "ProcessMessages" gives control back to windows.

Greatings from Denmark
Claus Ziegler
0
Industry Leaders: 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!

 

Expert Comment

by:98113772
ID: 1349134
I'm running this process on Windows NT, I don't know if this has anything to do with performance, but when I run:

Repeat
   Application.ProcessMessages;
Until Application.Terminated;

Some 97% of the CPU gets used.  When I start up other processes, the other processes have to fight for CPU usage with this process.
0
 

Author Comment

by:mozack
ID: 1349135
Yes, but it only uses the 97% when noone else needs it. As you can see, it will get lower and lower when you starts more processes up.

Greatings from Denmark
Claus Ziegler
0
 

Expert Comment

by:98113772
ID: 1349136
Exactly, whereas a real Sleep() would not use any CPU at all.
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi Firemonkey Need Sample for Online Shopping Example. 2 193
Delphi Yen format 3 62
How to build JSON File in Delphi 6 3 71
RESTRequest Parameter 4 54
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

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