I have a .NET Core application (desktop app with Avalonia) which needs to launch another process (most likely itself or another similar application).
The requirement is similar in nature to this question from almost a decade ago, but the answers posed there haven't worked for me - either they cause the main app to stay open until the second is closed or kills off the second to close the first.
The child process should be able to continue running when tha main application closes. As far as I'm aware, the ProcessStartInfo.UseShellExecute
property should allow for this.
//this will be called like LaunchNoOutput("C:\\Apps\\AnotherApp.exe")
public static void LaunchNoOutput(string exec) {
var process = new Process {
StartInfo = new ProcessStartInfo {
FileName = exec,
UseShellExecute = true,
CreateNoWindow = true
}
};
process.Start();
}
When the above code is run, the launched app (i.e. child) stays open as expected, but if I close the original app (i.e. parent) it will close the child app as well.
Is there a way to keep the child process running or detach it from the parent, so that calling Environment.Exit(0)
on the parent does not cause the child to exit as well?