如代码:
 Process process = new Process();
            process.StartInfo.FileName = "explorer.exe";
            process.StartInfo.Arguments = "d:\\hssy";
            process.StartInfo.CreateNoWindow = true;
            process.EnableRaisingEvents = true;
            process.Exited += new EventHandler(process_Exited);
            process.Start();
            process.WaitForExit();
        }        void process_Exited(object sender, EventArgs e)
        {
            MessageBox.Show("ok");
        }
=================
运行时,当打开外部程序后,Exited事件也随之触发了,而此时那个外部程序并没有关闭。
如何在其关闭时得到消息呢?

解决方案 »

  1.   


    你能确定你看到"那个外部程序"就是你刚刚调用的吗?存在这种可能,你启动的Explore.exe把参数传给某个桌面窗口(另一个程序),然后退出。你启动的程序是退出了,但你看到文件夹打开了。
      

  2.   

    进程是一个内核对象, 内核对象 跟 waithandle 有千丝万缕关系,不同内核对象激发有不同机制.了解这些你就会了.
      

  3.   

     p.ErrorDataReceived += new DataReceivedEventHandler(p_ErrorDataReceived); static void p_ErrorDataReceived(object sender, DataReceivedEventArgs e)
            {
                if (e.Data == null)
                    {
                   //此时外部程序已关闭
    }
                
            }