1

可能重复:
使用 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) { ... } 
    }

...对此有什么想法吗?

4

0 回答 0