Jump to content

Recommended Posts

Posted

Does anyone have suggestions on why it would be the case that I would call a program using CreateProcess and it (the called program) would not run for about a minute (like above)? I have a WaitForSingleObject call and it seems to be hanging on that in execution...


Posted

I figured this one out. For NT-based systems (like XP), you need to define SYNCHRONIZE as a attribute for the process in CreateProcess if you want to use any of the wait functions with it.

Posted

While you can use a WaitForSingleOjbect on creation, you might want to investigate WaitForInputIdle instead, as this function will actually wait through the called function's initialization routine, until the called process is idle (waiting for input) - this is "safer" than just an object wait, because if this fails you have chances to do things like break in and dump the called process if it fails to initialize in your try/except blocks or if blocks, which is always nice when debugging.

Posted
While you can use a WaitForSingleOjbect on creation, you might want to investigate WaitForInputIdle instead, as this function will actually wait through the called function's initialization routine,

Isn't WaitForInputIdle used to wait until the process loads, while WaitForSingleObject is used to wait for the process to complete? That was always my understanding (and I use both depending on the flags I pass the routine I use to call other programs)...

Posted
Isn't WaitForInputIdle used to wait until the process loads, while WaitForSingleObject is used to wait for the process to complete? That was always my understanding (and I use both depending on the flags I pass the routine I use to call other programs)...

That is correct - I was assuming you weren't wanting to wait (due to your post about the wait time for the launch), but if you want to return to the caller, you are right :).

Posted
That is correct - I was assuming you weren't wanting to wait (due to your post about the wait time for the launch), but if you want to return to the caller, you are right :).

The problem was that there was a very long time that it would take for the program to even come up (a minute or more). In my testing, the code would be successful to the Wait statement (either one) coded after the CreateProcess, but would hang at the wait statement. If I removed the wait, the program would come up instantaneously. As the original solution post indicated, NT based OSes require the SYNCHRONIZE tag when the process is created if Wait functions are to be used, so that deadlock may not occur (what I was observing), and the problem was solved once that was added to my CreateProcess call.

Thanks for your time! :thumbup

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...