父程序未启动子程序[已关闭]

问题描述 投票:0回答:1

我正在尝试创建一个启动子程序的父程序。当我运行父进程时,一切看起来都很好,但子进程还没有启动。

这是我的代码:

class Program
{
    static void Main(string[] args)
    {
        while (true)
        {
            // Start the child process
            Process childProcess = new Process();
            childProcess.StartInfo.FileName = "myPath"; 
            childProcess.StartInfo.UseShellExecute = false;
            childProcess.StartInfo.RedirectStandardOutput = true;

            try
            {
                childProcess.Start();
                Console.WriteLine("Child program started.");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error starting child process: {ex.Message}");
                continue; // Restart the loop to retry starting the child process
            }
//more code

当我运行它时,它会打印“子程序已启动”。但实际上还没有开始。 这可能是什么问题?

c# parent-child
1个回答
0
投票

确保它们位于同一名称空间中,您可能无法找到您的类。另请检查您是否使用了正确的访问修饰符。最后,确保子进程在启动后立即终止。

© www.soinside.com 2019 - 2024. All rights reserved.