在Process A中 Process.Start 一个Process B问题:如何在Process B 中 结束 Process A?谢谢。

解决方案 »

  1.   

    http://blog.csdn.net/tianyinlove/article/details/5270171
    看看这个应该能帮到你,进程之间应该没有父与子的关系。都是相互独立的。所以你可以通过进程名称关闭试试
      

  2.   

    在A中,B Process Start之后WaitForExit,然后A自己关闭自己
      

  3.   

    如果B可以接受命令行参数就行,将A的ProcessID传给B,B中就可以根据ProcessID去关闭一个进程
      

  4.   


                Process p = new Process();
                p.StartInfo.FileName = "notepad.exe";
                p.Start();
                p.WaitForExit();
                Environment.Exit(0);
      

  5.   

    那就像4L说的,在B的Main函数的args中把A的ProcessId传进来,B做完之后根据ProcessId把A进程结束掉。A.exe
    Process proB = new Process();
    proB.StartInfo.FileName = "B.exe";
    proB.StartInfo.Arguments = Process.GetCurrentProcess().Id.ToString();
    proB.Start();B.exe
    static void Main(string[] args)
    {
    int proAId;
    if(args.Length > 0)
    {
    int.TryParse(args[0], out proAId);
    }
    // do something
    if(proAId > 0)
    {
    Process proA = Process.GetProcessById(proAId);
    if(proA != null)
    {
    proA.Kill();
    }
    }
    }还有一个方法就是在B中根据A的名字找到A进程,然后关掉B.exe
    Process proA = Process.GetProcessesByName("A.exe").FirstOrDefault();
    if(proA != null)
    {
    proA.Kill();
    }