我想从当前执行进程A.exe启动一个新进程B.exe.
一旦B.exe启动,我想杀死A.exe(当前正在执行的进程).
虽然我可以启动B.exe但我无法关闭当前的进程,即A.exe.
我使用的代码是:
//Start the BT Setup Process
ProcessStartInfo startInfo = new ProcessStartInfo(@"C:\TEST\B.exe");
Process.Start(startInfo);
//Terminate the FSA
Process[] myProcess = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName);
foreach (Process process in myProcess)
{
process.CloseMainWindow();
//all the windows messages has to be processed in the msg queue
//hence call to Application DoEvents forces the MSG
Application.DoEvents();
}
Run Code Online (Sandbox Code Playgroud)