首页 > 解决方案 > Starting a separate exe and exiting the current programm

问题描述

I am trying to start a second exe-program from within a c# program. This is my current code:

Process p = new Process();
p.StartInfo.FileName = System.Windows.Forms.Application.StartupPath + "\\HASy-Diag.exe";
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.Arguments = "git-synchro " + args[1];
p.StartInfo.UseShellExecute = false;
p.Start();

But here is the catch: I want to exit my program right after I started the second exe.

The point is, that I have to do some asynchronous work, which cannot be in the same process as the programm. Note here, that is has to be in another process, not another thread. The reason is, that I want to do some work next to a build from an IDE. Running commands before and after the build is implemented in that IDE. The IDE (Keil here) waits, until the prebuild-process is finished (thats why I have to stop it) and then starts to build.

I want to retrieve information while the IDE builds the project (to essentially save time). So I want to start a new process from within a process.

is that possible? Any process I start with then given code above does not execute if you exit the full program. This code only executes if I have p.waitForExit() in the code.

标签: c#

解决方案


Use p.WaitForExit with parameter - pass 0 miliseconds, so your app will not wait but continue normally:

p.WaitForExit(0);

This method returns true if process ended and false if it is still in progress, but in your case it will not matter.


推荐阅读