使用process.waitforexit时(正在中止线程错误) [英] Thread was being aborted error when using process.waitforexit()

查看:1608
本文介绍了使用process.waitforexit时(正在中止线程错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有那么它连续执行多次低于code正从一个while循环调用。有时,但并非总是如此,我最终得到一个线程已被中止的p.WaitforExit错误()。没有人有任何见解呢?我应该打电话p.WaitForExit后p.Close()?

 字符串outputFileName = Path.Combine(Path.GetDirectoryName(recordingFileName),Guid.NewGuid()+.MPG);
        的ProcessStartInfo的StartInfo =新的ProcessStartInfo(ffmpegfileName);
        startInfo.Arguments =-i \\+ recordingFileName +\\-r 30 -sameq \\+ outputFileName +\\;
        startInfo.WindowStyle = ProcessWindowStyle.Hidden;
        进程p =的Process.Start(StartInfo的);
        p.WaitForExit();
        如果(p.Exit code!= 0)
        {
            抛出新的异常(+ p.Exit code.ToString(CultureInfo.InvariantCulture)+与退出code退出,);
        }
        返回outputFileName;

主题已被中止。
mscorlib程序
 在System.Threading.WaitHandle.WaitOneNative(SafeWaitHandle的WaitHandle,UInt32的millisecondsTimeout,布尔hasThreadAffinity,布尔exitContext)
 在System.Threading.WaitHandle.WaitOne(Int64的超时时间,布尔exitContext)
 在System.Diagnostics.Process.WaitForExit(的Int32毫秒)
 在System.Diagnostics.Process.WaitForExit()


解决方案

如果您是从一个ASP.NET页面调用它,你所看到的例外是最有可能的,你打的请求页面的执行超时结果并且它被中止。该错误是在p.WaitforExit()行,因为这是你的ASP.NET页面,而这是等着你开始回归过程。您可以更改网络配置文件的默认执行超时(110秒2.0)为您的ASP.NET应用程序。

 <的httpRuntime executionTimeout =600>

或通过在只有网页的页面code:

  HttpContext.Current.Server.ScriptTimeout

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

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

这篇关于使用process.waitforexit时(正在中止线程错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆