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).<
If you're falling into this quest of starting a process, and kill your own process after, use Environment.Exit(0)
, not Application.Exit()
.
Why do you want to close A
from B
while A
cat start B
and then close by itself?
Process.Start("A.exe");
Process.GetCurrentProcess().Kill(); // or Application.Exit(); or anything else
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.
I know this is old but in .net 4.0 you can do
ProcessStartInfo startInfo = new ProcessStartInfo(@"C:\TEST\B.exe");
startInfo.UseShellExecute = true;//This should not block your program
Process.Start(startInfo);
Then Application.Exit or whatever I tested with a winforms application using the close form method after launching a console app that just blocks on Console.readline();
Try Process.Kill() instead of Process.CloseMainWindow().