Start a new process and Killing the current process

后端 未结 5 1367
无人共我
无人共我 2020-12-31 04:15

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).<

相关标签:
5条回答
  • 2020-12-31 04:40

    If you're falling into this quest of starting a process, and kill your own process after, use Environment.Exit(0), not Application.Exit().

    0 讨论(0)
  • 2020-12-31 04:41

    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
    
    0 讨论(0)
  • 2020-12-31 04:43

    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.

    0 讨论(0)
  • 2020-12-31 04:51

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

    0 讨论(0)
  • 2020-12-31 04:54

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

    0 讨论(0)
提交回复
热议问题