Using WaitForExit() causes my program to hang
Using WaitForExit() causes my program to "hang" at this statement.
Without the WaitForExit() my program competes under 1 minute.
Please check my code below and let me know what I am doing incorrectly.
Dim m_oProc As New Process
Dim oInfo As ProcessStartInfooInfo = New ProcessStartInfo("some.wsf", sArgs)
oInfo.UseShellExecute = False
oInfo.RedirectStandardOutput = True
oInfo.RedirectStandardError = True
oInfo.CreateNoWindow = True
m_oProc.StartInfo = oInfoDim et As New StdErrorThread(m_oProc)
Dim t As New Thread(AddressOf et.ThreadProc)
et.ErrLogObj = ErrLogObjIf m_oProc.Start() Then
t.Start()
m_oProc.WaitForExit()
...Without the WaitForExit the "some.wsf" file completes within a minute.
With the WaitForExit the script does not complete and my code hangs.Why?
If I use WaitForExit(30000) then execution continues on the next line only AFTER 5 minutes!
Why?
- Changed TypeJialiang Ge [MSFT]MSFT, ModeratorThursday, October 29, 2009 11:13 AMthis is a question
Answers
- Hello Siggy01
In which thread are you calling m_oProc.WaitForExit()? Is it the WinForm UI thread? If yes, please move the call to a worker thread. It's not recommended to wait in UI thread for I/O or external applications that may take a long time.
Regards,
Jialiang Ge
MSDN Subscriber Support in Forum
If you have any feedback of our support, please contact msdnmg@microsoft.com.
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer bySiggy01 Friday, November 06, 2009 10:54 PM
- Hi Jialiang,
Thanks for your response and sorry about the delayed response from me.
I have now created a separate thread for the stdout as well as the stderr.
So in effect I have the main thread plus a thread for each of the 2 results that I am receiving.
The WaitForExit is being executed on the main thread and all is working as it should.
Once again thanks for pointing me in the correct direction.
Regards
Siggy- Marked As Answer bySiggy01 Friday, November 06, 2009 10:54 PM
All Replies
... correction to my comment above, the "WaitForExit(30000)" should read "WaitForExit(300000)"!
- Hello Siggy01
In which thread are you calling m_oProc.WaitForExit()? Is it the WinForm UI thread? If yes, please move the call to a worker thread. It's not recommended to wait in UI thread for I/O or external applications that may take a long time.
Regards,
Jialiang Ge
MSDN Subscriber Support in Forum
If you have any feedback of our support, please contact msdnmg@microsoft.com.
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer bySiggy01 Friday, November 06, 2009 10:54 PM
- You are redirecting output but there's no evidence that you are actually reading the output. Doing it after the WaitForExit() call is usually too late. The redirected app's output buffer will fill up and then it will block, waiting for somebody to empty the buffer. Use BeginOutputReadLine() to avoid this.
Hans Passant. - Hello Siggy01
How are you? Do you get any progress in the issue? If you have any other questions, please feel free to post here.
Regards,
Jialiang Ge
MSDN Subscriber Support in Forum
If you have any feedback of our support, please contact msdnmg@microsoft.com.
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. - Hi Jialiang,
Thanks for your response and sorry about the delayed response from me.
I have now created a separate thread for the stdout as well as the stderr.
So in effect I have the main thread plus a thread for each of the 2 results that I am receiving.
The WaitForExit is being executed on the main thread and all is working as it should.
Once again thanks for pointing me in the correct direction.
Regards
Siggy- Marked As Answer bySiggy01 Friday, November 06, 2009 10:54 PM


