Console application hangs when called from Process.Start

C

chad

Hi,

I am using Process.Start() to call a console application from ASP.NET
page. When the code is executed, the Console application is opened.
When it is done, it should have been terminated but it is not. I have
placed WaitForExit(20000) to limit the execution time to 20 seconds and
if it does not terminate then it will be forced close. The question is
why wouldn't the application exit by itself when it is done as it
should be (it was idle). Please see the code below.

System.Diagnostics.ProcessStartInfo processInfo = new
System.Diagnostics.ProcessStartInfo(path, parameters);
processInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
processInfo.RedirectStandardOutput = true;
processInfo.UseShellExecute = false;
processInfo.CreateNoWindow = true;

System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo = processInfo;
process.Start();
process.WaitForExit(20000);
process.Kill();


Thanks!!
 
W

wfairl

You're redirecting the output so you're going to have to read from the
output stream or the process will hang once it fills (I don't remember
offhand how many bytes it can buffer). If you're doing this in .net 1
you're going to have to poll the stream from another thread, in 2.0 you
can use BeginOutputReadLine instead.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top