ProcessStartInfo hanging on “WaitForExit”? Why?

前端 未结 22 1883
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 02:59

I have the following code:

info = new System.Diagnostics.ProcessStartInfo(\"TheProgram.exe\", String.Join(\" \", args));
info.CreateNoWindow = true;
info.Win         


        
22条回答
  •  囚心锁ツ
    2020-11-22 03:17

    Mark Byers' answer is excellent, but I would just add the following:

    The OutputDataReceived and ErrorDataReceived delegates need to be removed before the outputWaitHandle and errorWaitHandle get disposed. If the process continues to output data after the timeout has been exceeded and then terminates, the outputWaitHandle and errorWaitHandle variables will be accessed after being disposed.

    (FYI I had to add this caveat as an answer as I couldn't comment on his post.)

提交回复
热议问题