我想从当前执行进程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)
你为什么要关闭A
的B
,而A
猫开始B
,然后自行关闭?
Process.Start("A.exe");
Process.GetCurrentProcess().Kill(); // or Application.Exit(); or anything else
Run Code Online (Sandbox Code Playgroud)
小智 6
如果你正在进入这个开始一个过程的任务,并在之后杀死你自己的过程,请使用Environment.Exit(0)
,而不是Application.Exit()
.
归档时间: |
|
查看次数: |
38495 次 |
最近记录: |