Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CreateProcess with wait causes lockup.

Status
Not open for further replies.

Glenn9999

Programmer
Jun 19, 2004
2,312
US
I'm running a program with CreateProcess and using WaitforSingleObject to pause execution. The called program, however, is locking up to the point that it doesn't execute at all. The code is getting to the WaitforSingleObject line.

What explains this, and how would you solve it?
 
Okay, I let my calling program set for about a minute and the called program finally came up about a minute into the run. Hope it helps to explain what is going on.
 
Okay, it seems this one is figured out. It seems if you use any of the wait functions on Windows NT based systems, the potential is there for the calling process to deadlock with the called process, causing anything from that delay to a lockup (I would guess).

To use faq102-6048 as a reference:

Code:
 if (CreateProcess(nil, Pchar(Filename +' '+ Params), 
    Nil, Nil, False, 
    NORMAL_PRIORITY_CLASS+SYNCHRONIZE,
    Nil, nil { pchar(extractfilepath(Params))},  
    StartupInfo, ProcessInfo)) then
      begin
        WaitResult := WaitForSingleObject(ProcessInfo.hProcess, Timeout);

As a side note, my research into this problem suggested that WaitForInputIdle might not be a bad idea between the CreateProcess and the WaitForSingleObject calls.

Code:
WaitForInputIdle(ProcessInfo.HProcess, INFINITE);

Hope this helps out someone...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top