Following is the application code. some time p.StandardOutput.ReadLine(); works fine but some time it hang up i tried all things but still getting this error
Pr
Your program is correct if the called program always outputs exactly one line, and that line is shorter than the buffer employed by the system.
If it doesn't output a line, ReadLine
won't return. So your program is broken in this case.
If it outputs too much, the output buffer runs full, and the called program will block on its Write
call, until somebody reads enough from the output. Since you never read from the output buffer beyond the first line, this block will last forever, and thus the called program will never terminate. This in turn causes your program to deadlock at p.WaitForExit()
.
The documentation clearly states:
Do not wait for the child process to exit before reading to the end of its redirected stream.
The code example avoids a deadlock condition by calling
p.StandardOutput.ReadToEnd
beforep.WaitForExit
. A deadlock condition can result if the parent process callsp.WaitForExit
beforep.StandardOutput.ReadToEnd
and the child process writes enough text to fill the redirected stream. The parent process would wait indefinitely for the child process to exit. The child process would wait indefinitely for the parent to read from the fullStandardOutput
stream.