小编sri*_*tsa的帖子

启动新流程并终止当前流程

我想从当前执行进程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)

c# process

16
推荐指数
2
解决办法
4万
查看次数

标签 统计

c# ×1

process ×1