[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Blocking on WinExec in Delphi 1.0

Posted on 1997-10-29
6
Medium Priority
?
1,068 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 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

868 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