开始一个新的进程和杀死当前进程 [英] Start a new process and Killing the current process

查看:252
本文介绍了开始一个新的进程和杀死当前进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从目前的执行过程A.exe时启动一个新的进程B.EXE。



和尽快B.EXE推出我要杀死A.EXE(当前执行的进程)。



虽然我可以开始B.EXE我无法关闭我目前的进程,即a.exe的。



代码我用的是:

  //启动BT安装过程
的ProcessStartInfo的StartInfo =新的ProcessStartInfo(@C:\TEST\B.exe);
的Process.Start(StartInfo的);

//终止FSA
过程[] = myProcess Process.GetProcessesByName(Process.GetCurrentProcess()ProcessName);
的foreach)(在myProcess工艺过程)
{
process.CloseMainWindow(;
//所有窗口的消息已经在排队味精
进行处理//因此调用应用程序的DoEvents强制味精
Application.DoEvents();
}


解决方案

尝试的 Process.Kill()代替的 Process.CloseMainWindow()


I want to start a new process B.exe from the current executing process A.exe.

And as soon as B.exe is launched I want to kill A.exe (the current executing process).

Though I can start B.exe I cannot close my current process i.e A.exe.

Code I use is:

//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();
}

解决方案

Try Process.Kill() instead of Process.CloseMainWindow().

这篇关于开始一个新的进程和杀死当前进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆