下面的代码是从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()