2

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?

Riccorbypro
  • 143
  • 2
  • 8
  • From what I can gather, a terminating a process does not terminate its children. Are you sure there is no issue in "AnotherApp.exe" that causes it to exit or crash once the parent process terminates? See https://learn.microsoft.com/en-us/windows/win32/procthread/terminating-a-process – JonasH May 22 '20 at 09:20
  • Having set the launched app to an exe that I can then attach a debugger to in VS shows that the other executable runs normally until the original app is exited. At that point it seems to just kill the launched app, disconnecting the debugger without notification. – Riccorbypro May 22 '20 at 09:25

0 Answers0