Alex Rivera | Logout

Start a new process and Killing the current process

Asked 2010-11-25T16:06:57.887
21

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

1 Answer

2

If you just want to close the current process you should be able to just call Application.Exit rather than looping through and closing processes.

answered 2010-11-25T16:09:44.737

Your Answer