使用process.waitforexit()时线程被中止错误

我在下面的代码是从while循环调用的,所以它连续多次执行。 有时,但并不总是,我最终得到一个线程是在p.WaitforExit()上被中止错误。 有没有人对此有任何见解? 我应该在p.WaitForExit之后调用p.Close()吗?

string outputFileName = Path.Combine(Path.GetDirectoryName(recordingFileName), Guid.NewGuid() + ".mpg"); ProcessStartInfo startInfo = new ProcessStartInfo(ffmpegfileName); startInfo.Arguments = "-i \"" + recordingFileName + "\" -r 30 -sameq \"" + outputFileName + "\""; startInfo.WindowStyle = ProcessWindowStyle.Hidden; Process p = Process.Start(startInfo); p.WaitForExit(); if (p.ExitCode != 0) { throw new Exception("exited with an exit code of " + p.ExitCode.ToString(CultureInfo.InvariantCulture) + "."); } return outputFileName; 
 威胁已经被清除了。
 mscorlib程序
 在System.Threading.WaitHandle.WaitOneNative(SafeWaitHandle waitHandle,UInt32 millisecondsTimeout,Boolean hasThreadAffinity,Boolean exitContext)
 在System.Threading.WaitHandle.WaitOne(Int64 timeout,Boolean exitContext)
 在System.Diagnostics.Process.WaitForExit(Int32毫秒)
 在System.Diagnostics.Process.WaitForExit() 

如果您从ASP.NET页面调用它,您看到的exception很可能是因为您在页面请求上达到执行超时并且它正在中止。 错误发生在p.WaitforExit()行上,因为这是您的ASP.NET页面在等待您开始返回的进程时的位置。 您可以在ASP.NET应用程序的Web配置文件中更改默认执行超时(在2.0中为110秒)。

  

或仅通过该页面的页面中的代码:

  HttpContext.Current.Server.ScriptTimeout 

http://msdn.microsoft.com/en-us/library/e1f13641.aspx