Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

Question Process.Exited event works but functions do not call

Discussion in 'Windows' started by vagelis199, May 9, 2023.

  1. vagelis199

    vagelis199

    Joined:
    Jul 27, 2012
    Posts:
    167
    Hi, I have the following code:

    Code (CSharp):
    1.  void StartAC()
    2.     {
    3.  
    4.         GameRunning_UI.SetActive(true);
    5.         var GameProcess = Process.Start(new ProcessStartInfo
    6.         {
    7.             FileName = Acs_exe_path,
    8.             WorkingDirectory = AcRootDirectory,
    9.         });
    10.  
    11.         if (GameProcess == null || GameProcess.HasExited)
    12.         {
    13.             UnityEngine.Debug.LogError("Failed to start game process!");
    14.             return;
    15.         }
    16.         GameProcess.EnableRaisingEvents = true;
    17.         GameProcess.Exited += p_Exited;
    18.  
    19.         // Log some debugging information
    20.         UnityEngine.Debug.Log($"Game process started with ID {GameProcess.Id}");
    21.  
    22.     }
    23.     void p_Exited(object sender, EventArgs e)
    24.     {
    25.         GameExit();
    26.     }
    27.  
    28.     void GameExit(){
    29.         UnityEngine.Debug.Log("Game process exited!");
    30.         GameRunning_UI.SetActive(false);
    31.         Out_Script.GetResults();
    32.     }
    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?
     
  2. vagelis199

    vagelis199

    Joined:
    Jul 27, 2012
    Posts:
    167
    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