I have code below that is getting called from a while loop so it's executing multiple times in a row. Sometimes, but not always, I开发者_如何学运维 end up getting a thread was being aborted error on the p.WaitforExit(). Does anyone have any insight into this? should I be calling p.Close() after p.WaitForExit?
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()
If you are calling it from an ASP.NET page the Exception you are seeing is most likely a result of you hitting the Execution timeout on the Request for the page and it is being aborted. The error is on the p.WaitforExit() line because that is where your ASP.NET page was while it was waiting for the Process you started to return. You can change the default execution timeout (110 seconds in 2.0) in the web config file for your ASP.NET app.
<httpRuntime executionTimeout = "600" >
or via code in the page for that page only:
HttpContext.Current.Server.ScriptTimeout
http://msdn.microsoft.com/en-us/library/e1f13641.aspx
精彩评论