?
Solved

Blocking on WinExec in Delphi 1.0

Posted on 1997-10-29
6
Medium Priority
?
1,066 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
[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
  • 3
  • 2
6 Comments
 

Accepted Solution

by:
98113772 earned 200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month10 days, 10 hours left to enroll

765 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