RunInfo runInfo = new RunInfo();
Process process = new Process();
            process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.CreateNoWindow = true;
            process.StartInfo.RedirectStandardInput = true;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError = true;
            process.StartInfo.FileName = exeFilePath;
            process.Start();
            runInfo.RunMemory = (process.PeakWorkingSet64);//获取内存大小 , 以字节为单位
            Standard_IN_OUT ob = new Standard_IN_OUT(process, inFilePath);
            Thread threadIn = new Thread(ob.RedirectProcessInStream);
            Thread threadOut = new Thread(ob.RedirectProcessOutStream);
            threadIn.Start();
            threadOut.Start();
            process.WaitForExit();代码如上 , 其中RunInfo类保存process运行结果的相关信息 , ob.RedirectProcessInStream , ob.RedirectProcessOutStream分别是类Standard_IN_OUT的方法 , 通过重定向process的输入输出来运行“process调用的程序” , 比如exeFilePath值为“cmd" , 则两个线程threadIn和threadOut分别重定向fileName为”cmd"的这个process 的输入输出流 。 不太好说这个意思啊。哈现在的问题是这段代码运行完成之后两个线程有时却没有完成 , 难道process.WaitForExit()方法不等待两个线程运行完成吗 ?如果不等待两个线程完成的话 , 那process.waitForExit()方法的作用是什么 , 是等待process完成吗 ? 如果是这样的话又有一个疑问了 , 两个线程不完成 , process如何完成的呢 ?我想要实现这样一个功能 , 在两个线程完成之后才运行process.WaitForExit()之后的代码 , 如何实现 ? 先谢谢诸位了

解决方案 »

  1.   

    在两个线程完成之后才运行process.WaitForExit()之后的代码
    可以通过设置信号量来判断,要参考多线程
      

  2.   

    process.waitForExit()是等你输入个响应,它就退出,这个是命令窗口,不会跟你的线程扯上关系的!
      

  3.   

    Process.WaitForExit ()  Instructs the Process component to wait indefinitely for the associated process to exit. 
    Supported by the .NET Compact Framework. 
     
    Process.WaitForExit (Int32)  Instructs the Process component to wait the specified number of milliseconds for the associated process to exit. 
    Supported by the .NET Compact Framework.