我想从当前执行进程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();
}
顺便说一句我不想使用Process.Kill()方法 – srivatsa 2010-11-25 16:09:16
为什么你不想使用`Process.Kill()`方法? – abatishchev 2010-11-25 16:10:01
因为它不会调用我的清理代码 – srivatsa 2010-11-25 16:17:46