【问题标题】:Thread was being aborted error when using process.waitforexit()使用 process.waitforexit() 时线程被中止错误
【发布时间】:2010-01-08 14:37:51
【问题描述】:

我下面的代码是从 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 毫秒超时,布尔 hasThreadAffinity,布尔 exitContext)
 在 System.Threading.WaitHandle.WaitOne(Int64 超时,布尔型 exitContext)
 在 System.Diagnostics.Process.WaitForExit(Int32 毫秒)
 在 System.Diagnostics.Process.WaitForExit()

【问题讨论】:

    标签: c# asp.net multithreading process


    【解决方案1】:

    如果您从 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-16
      相关资源
      最近更新 更多