C# 已退出的事件在进程结束后立即激发。启动

C# 已退出的事件在进程结束后立即激发。启动,c#,unity3d,eventhandler,system.diagnostics,C#,Unity3d,Eventhandler,System.diagnostics,我正在使用神经网络(NN)做一个程序地图生成应用程序,我正在使用Unity作为我的图形引擎。我的操作系统是Ubuntu18.04LTS,我使用的是VSCode和C#编码。 用户绘制他/她希望地图看起来像什么的低级表示,然后NN计算该输入并输出高度地图。 然后,我将高度贴图应用到网格上 为此,我使用Process类创建了一个终端,并使用bash命令执行适当的脚本。这是可行的,但我得出的结论是我的映射没有更新,所以我决定使用EventHandler,它只在我启动的进程退出时触发一个信号并执行一个小方

我正在使用神经网络(NN)做一个程序地图生成应用程序,我正在使用Unity作为我的图形引擎。我的操作系统是Ubuntu18.04LTS,我使用的是VSCode和C#编码。 用户绘制他/她希望地图看起来像什么的低级表示,然后NN计算该输入并输出高度地图。 然后,我将高度贴图应用到网格上

为此,我使用Process类创建了一个终端,并使用bash命令执行适当的脚本。这是可行的,但我得出的结论是我的映射没有更新,所以我决定使用EventHandler,它只在我启动的进程退出时触发一个信号并执行一个小方法。 这里的核心问题是在我启动流程后立即触发事件。代码如下:

public void ConsoleWriter()
        {
            Process proc = new System.Diagnostics.Process();

            proc.StartInfo.FileName = "/bin/bash";
            string command = "gnome-terminal -- /bin/bash -c 'cd $HOME; cd pix2pix-tensorflow/ ;python3 tools/dockrun.py python singleproduction.py --input_file ~/pix2pix-tensorflow/SavedScreen.png --model_dir ~/pix2pix-tensorflow/single_test --output_dir ~/pix2pix-tensorflow/ --output_file out_SavedScreen.png;'";

            proc.StartInfo.Arguments = "-c \" " + command + " \"";
            proc.EnableRaisingEvents = true;
            proc.StartInfo.UseShellExecute = false;
            proc.StartInfo.RedirectStandardOutput = true;
            proc.Exited += new EventHandler(PlisDraw);
            proc.Start();
            proc.WaitForExit();
        }
PlisDraw方法有两行:

 public void PlisDraw( object sender, System.EventArgs e)
        {
            UnityEngine.Debug.Log("entered PlsDraw");
            mapUpdate.GenerateMap();
        }
我已经做了很多故障排除,我遇到的主要问题是,创建的进程的PID在我的系统监视器上的任何监视器中都不存在(top、glanses、pstree、pstree和几个不同的greps和Ubuntu系统监视器)。 第一幅图以统一形式显示控制台输出,我们可以在第一个条目中看到相关的ID,在第二幅图中,我们裁剪了pstree命令,以仅显示gnome终端树(代码打开的终端窗口是一个显示“sudo”的窗口)因为每次在不同的终端窗口中执行脚本时,它都会要求输入密码。)PID明显不同,我完全不知道为什么会发生这种情况……如果确实发生了这种情况,可以理解的是进程。退出会触发,因为据代码所知,没有PID=关闭的进程,或者我完全误解了这个问题?任何帮助都将不胜感激

PS:为了完整起见,以下是所有控制台输出的代码:

public void ConsoleWriter()
        {
            Process proc = new System.Diagnostics.Process();

            proc.StartInfo.FileName = "/bin/bash";
            //string command = "firefox";

            string command = "gnome-terminal -- /bin/bash -c 'cd $HOME; cd pix2pix-tensorflow/ ;python3 tools/dockrun.py python singleproduction.py --input_file ~/pix2pix-tensorflow/SavedScreen.png --model_dir ~/pix2pix-tensorflow/single_test --output_dir ~/pix2pix-tensorflow/ --output_file out_SavedScreen.png;'";
            //string command = "gnome-terminal -x bash -ic";
            // este funciona gnome-terminal -- /bin/bash -c 
            proc.StartInfo.Arguments = "-c \" " + command + " \"";
            proc.EnableRaisingEvents = true;
            proc.StartInfo.UseShellExecute = false;
            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.RedirectStandardError = true;
            proc.StartInfo.RedirectStandardInput = true;

            proc.Exited += new EventHandler(PlisDraw);
            proc.Start();
            UnityEngine.Debug.Log("PROC ID : " + proc.Id);
            Process localById = Process.GetProcessById(proc.Id);
            UnityEngine.Debug.Log(localById);
            proc.WaitForExit();
            string output = proc.StandardOutput.ReadToEnd();
            string error = proc.StandardError.ReadToEnd();
            // UnityEngine.Debug.Log("error : " + error);
            // UnityEngine.Debug.Log("output : " + output);
            UnityEngine.Debug.Log("exitcode: " + proc.ExitCode);
            UnityEngine.Debug.Log("after start : " + proc.HasExited);


        }

为了子孙后代,我相信proc.ID检索的进程ID是启动进程的线程的ID,并且该线程在启动进程后立即死亡,因此这可能是立即创建ExitCode的原因,但它仍然没有解释为什么触发时调用的方法不能。实际上,我将该方法附加到UnityGUI中的一个按钮上,它可以正常工作,从而确定该方法如何不工作。希望这些信息对某些人有用。为了子孙后代,我相信proc.ID检索的进程ID是启动进程的线程的ID,该线程在启动进程后立即死亡,因此,这可能是立即创建ExitCode的原因,但它仍然没有解释为什么触发时调用的方法不会创建ExitCode。实际上,我将该方法附加到UnityGUI中的一个按钮上,它可以正常工作,从而确定该方法如何不工作。希望这些信息对某人有用。