我下面的代码从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毫秒超时, bool hasThreadAffinity, bool exitContext)
在System.Threading.WaitHandle.WaitOne处(Int64超时, bool 值exitContext)
在System.Diagnostics.Process.WaitForExit(Int32毫秒)
在System.Diagnostics.Process.WaitForExit()
最佳答案
如果从ASP.NET页面调用它,则所看到的异常很可能是由于您击中了页面请求上的执行超时而被中止的。该错误在p.WaitforExit()行上,因为这是ASP.NET页在等待开始返回的进程时所处的位置。您可以在ASP.NET应用程序的Web配置文件中更改默认执行超时(2.0中为110秒)。
<httpRuntime executionTimeout = "600" >
或仅通过该页面中页面中的代码进行操作:
HttpContext.Current.Server.ScriptTimeout
http://msdn.microsoft.com/en-us/library/e1f13641.aspx
关于c# - 使用process.waitforexit()时线程被中止错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2028241/