Console application hangs when called from Process.Start

Discussion in 'ASP .Net' started by chad, Apr 6, 2006.

  1. chad

    chad Guest

    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!!
     
    chad, Apr 6, 2006
    #1
    1. Advertising

  2. chad

    Guest

    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.
     
    , Apr 6, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    10
    Views:
    3,150
  2. Mike
    Replies:
    9
    Views:
    1,444
    Robbe Morris [C# MVP]
    Nov 30, 2005
  3. Alexander Widera

    process.start() program hangs

    Alexander Widera, May 22, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    6,250
    Alexander Widera
    May 31, 2006
  4. Replies:
    7
    Views:
    929
    John Saunders
    Mar 20, 2007
  5. Tim Shadel

    Gem hangs => TCPSocket.write hangs

    Tim Shadel, Jul 23, 2005, in forum: Ruby
    Replies:
    1
    Views:
    423
    Ville Mattila
    Jul 24, 2005
Loading...

Share This Page