如何使C#进程保持活动状态(节点服务器)

时间:2018-11-08 13:09:02

标签: c# server process

你好,我正在用c#创建一个打开node.js的进程,到目前为止,效果很好,但是当我从cmd执行相同的命令时,该进程似乎结束了,并且提示它仍然存在,我该如何实现这一目标?来自C#?这是流程的代码

     private void buttonStartLLodiAgent_Click(object sender, EventArgs e)
    {

        //proc.WaitForExit();
        ProcessStartInfo psi = new ProcessStartInfo();
        psi.CreateNoWindow = true;
        psi.RedirectStandardInput = true;
        psi.RedirectStandardOutput = true;
        psi.UseShellExecute = false;
        psi.RedirectStandardError = true;
        psi.FileName = "node.exe";
        psi.Arguments = AppDomain.CurrentDomain.BaseDirectory + "/LLodiAgent/main.js";
        using (var process = Process.Start(psi))
        {
            //labelStatusLLodiAgent.Text = "Active";
            process.BeginOutputReadLine();
            process.OutputDataReceived += proc_OutputDataReceived;
            //process.WaitForExit();
        }

    }
    public void proc_OutputDataReceived(object sender, DataReceivedEventArgs e)
    {
        outputConsole.Text = outputConsole.Text + "\r\n" + e.Data;
    }

我正确地输出了,但是似乎Node服务没有启动,所以我猜它执行了,但是随后杀死了它。 如何使服务器保持活动状态并C#接收数据?

预先感谢(这是我的第一篇文章)

0 个答案:

没有答案