假设现在我开启了两个同名进程,它们的PID分别为1和2,现在我用kill方法将2进程关闭了,但是1进程也自动退出了,这是怎么回事,请高手帮忙……

解决方案 »

  1.   

    我也不知道怎么回事,无图无信息//关闭制定进程
    System.Diagnostics.Process[] allProcess = System.Diagnostics.Process.GetProcesses();
                foreach (System.Diagnostics.Process thisprocess in allProcess)
                {
                    string processName = thisprocess.ProcessName;
                    if (processName.ToLower() == "1")
                    {
                        try
                        {
                            thisprocess.Kill();
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message);
                            return;
                        }
                    }
                }
      

  2.   

    1.taskkill /pid
    2.process 
      

  3.   

     先引用using System.Runtime.InteropServices;[DllImport("user32.dll", SetLastError = true)]
            public static extern int GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId);
            public void KillSpecialExcel()
            {            try
                {                if (excelApp != null)
                    {
                        int lpdwProcessId;
                        GetWindowThreadProcessId(new IntPtr(excelApp.Hwnd), out lpdwProcessId);
                        System.Diagnostics.Process.GetProcessById(lpdwProcessId).Kill();
                    }            }
                catch (Exception ex)
                {
                    Console.WriteLine("Delete Excel Process Error:" + ex.Message);
                }        }