再求救:我可以用process类的某些方法判断某一进程是否已结束吗?怎么写?

解决方案 »

  1.   

    命名空间是using System.Diagnostics;string name = "aaa";//程序进程名称
       int ProgressCount = 0123456;//判断进程是否运行的标识
       Process[] prc = Process.GetProcesses(); 
       foreach(Process pr in prc) //遍历整个进程
       {  
                if (name == pr.ProcessName)  //如果进程存在
                {     
                        ProgressCount = 0; //计数器清空
                         return;
                }  
       }
       if(ProgressCount!=0)//如果计数器不为0,说名所指定程序没有运行
       {
        try
        {
         //调用外部程序
         Process MyProcess = new Process();
         MyProcess.StartInfo.FileName = "d:/aaa.exe";
         MyProcess.StartInfo.Verb = "Open";
         MyProcess.StartInfo.CreateNoWindow = true;
         MyProcess.Start();
        }
        catch(Exception d)
        {
         MessageBox.Show(d.Message+"","提示!!!!");
        }
       }
       else
       {
        MessageBox.Show("对不起,本地已经有系统正在运行!\n.","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
       }  
      

  2.   

    我不太明白这段是什么意思,大侠能解说下吗? //调用外部程序
         Process MyProcess = new Process();
         MyProcess.StartInfo.FileName = "d:/aaa.exe";
         MyProcess.StartInfo.Verb = "Open";
         MyProcess.StartInfo.CreateNoWindow = true;
         MyProcess.Start();
      

  3.   

    还有在if (name == pr.ProcessName)  //如果进程存在
                {     
                        ProgressCount = 0; //计数器清空
                         return;
                }  
    这个return后,他就跳出去了,下面的都不执行了。。
     if(ProgressCount!=0)//如果计数器不为0,说名所指定程序没有运行
       {
        try
        {
         //调用外部程序
         Process MyProcess = new Process();
         MyProcess.StartInfo.FileName = "d:/aaa.exe";
         MyProcess.StartInfo.Verb = "Open";
         MyProcess.StartInfo.CreateNoWindow = true;
         MyProcess.Start();
        }
        catch(Exception d)
        {
         MessageBox.Show(d.Message+"","提示!!!!");
        }
       }
       else
       {
        MessageBox.Show("对不起,本地已经有系统正在运行!\n.","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
       }