我下面的代码是从 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;
Thread was being aborted.
mscorlib
at System.Threading.WaitHandle.WaitOneNative(SafeWaitHandle waitHandle, UInt32 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)
at System.Threading.WaitHandle.WaitOne(Int64 timeout, Boolean exitContext)
at System.Diagnostics.Process.WaitForExit(Int32 milliseconds)
at 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 http://msdn.microsoft.com/en-us/library/e1f13641.aspx
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)