Process.WaitForExit()抛出线程被中止?

时间:2012-07-15 09:52:36

标签: c# asp.net multithreading process

  

可能重复:
  Thread was being aborted error when using process.waitforexit()

这是堆栈跟踪

Message :Thread was being aborted.
   at System.Threading.WaitHandle.WaitOneNative(SafeWaitHandle waitHandle, UInt32 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)
   at System.Threading.WaitHandle.WaitOne(Int64 timeout, Boolean exitContext)
   at System.Threading.WaitHandle.WaitOne(Int32 millisecondsTimeout, Boolean exitContext)
   at System.Diagnostics.Process.WaitForExit(Int32 milliseconds)

代码如下:

    [WebMethod]
    public Double executeAsJob()
    {
            myThread = new Thread(new ParameterizedThreadStart(runThread));
            myThread.Start();
            return RUNNING;
    }

    public void runThread() {
            try {
                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo.FileName = ...;
                proc.StartInfo.Arguments = ...;
                proc.StartInfo.UseShellExecute = false;
                proc.Start();
                proc.WaitForExit(); // <-- THIS line throws the exception

                // Save exit code 
                iResult = proc.ExitCode;
            } catch (Exception e) { ... } 
    }

......有关于此的任何想法吗?

0 个答案:

没有答案