Process.Exited event works but functions do not call

Hi, I have the following code:

 void StartAC()
    {

        GameRunning_UI.SetActive(true);
        var GameProcess = Process.Start(new ProcessStartInfo
        {
            FileName = Acs_exe_path,
            WorkingDirectory = AcRootDirectory,
        });

        if (GameProcess == null || GameProcess.HasExited)
        {
            UnityEngine.Debug.LogError("Failed to start game process!");
            return;
        }
        GameProcess.EnableRaisingEvents = true;
        GameProcess.Exited += p_Exited;

        // Log some debugging information
        UnityEngine.Debug.Log($"Game process started with ID {GameProcess.Id}");

    }
    void p_Exited(object sender, EventArgs e)
    {
        GameExit();
    }

    void GameExit(){
        UnityEngine.Debug.Log("Game process exited!");
        GameRunning_UI.SetActive(false);
        Out_Script.GetResults();
    }

When I call StartAC() the GameRunning_UI gets activated the process starts, I get the log “Game process started with ID” in the console
and when I exit the process, GameExit() seems to get called, I get “Game process exited!” in the console. But anything else after do not continue. GameRunning_UI never gets disabled and neither does the GetResults() get called.

How I can solve this issue?

A solution i found is to create a bool set it to true once p_Exited gets called, and run the functions I want in Update with if statement.
Not sure if it’s the best approach tho

This is because p_Exited is being executed outside of the main thread and can not call call monobehavior or UI functions.

The proper way to address this would be to create a dispatcher that queues up method calls on the next main thread update