Skip to content

Child left stranded #32

Open
Open

Description

@Alienmario

If parent process exits or is killed through task explorer, the child process continues stranded.

It would be handy to have an option of automatically killing spawned processes. I've found this possible solution.

Environment
I am using .net 9 with Windows 11, calling the ExecFunction.Start() function from a AvaloniaUI app.

Activity

  1. Alienmario commented on Apr 5, 2025

    @Alienmario
    Author

    The linked approach works for me.

    1. Pass Environment.ProcessId.ToString() as an argument to the subprocess function.
    2. Inside the function:
    var parentProcess = Process.GetProcessById(Convert.ToInt32(args[x]));
    parentProcess.EnableRaisingEvents = true;
    parentProcess.Exited += (s, a) =>
    {
        Process.GetCurrentProcess().Kill(true);
    };
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions