日期:2014-05-20  浏览次数:20912 次

process的HasExited问题--打开多个word出错
我在程序中,想打开三次某个word文档,程序如下。但在打开第二次的时候,HasExited为ture,p.MainWindowHandle有异常发生,请问怎么回事?

for(int   i=0;i <3;i++)
{
System.Diagnostics.Process   p   =   new   System.Diagnostics.Process();


p.StartInfo.FileName   =   @ "C:\Program   Files\Microsoft   Office\OFFICE11\WINWORD.EXE ";
p.StartInfo.Arguments   =   "C:\\Documents   and   Settings\\wxl\\desktop\\test2.doc ";


p.Start();
while(!p.WaitForInputIdle(1000))
{}
IntPtr   tmep=p.MainWindowHandle;
}

------解决方案--------------------
一个word文档在一台机器上是不能打开多次的,这就是原因所在
就算你全面的进程已经退出了,但你到进程列表里面看一下,是不是还有word进程?