简体   繁体   English

当我的应用退出时,如何防止由Process.Start()启动的进程退出?

[英]How to prevent a process started by Process.Start() from exiting when my app exits?

my method... 我的方法

private static void RunAndExit(string command)
{
    var processInfo = new ProcessStartInfo
    {
        FileName = "cmd.exe",
        Arguments = "/c " + command,
        CreateNoWindow = false,
        UseShellExecute = true,
        RedirectStandardError = false,
        RedirectStandardOutput = false
     };
    }

I want the process started by RunAndExit() to continue to run after the app containing this method has exited. 我希望由RunAndExit()启动的进程在退出包含此方法的应用程序后继续运行。 Thanks for any help! 谢谢你的帮助!

Your code will already achieve that, so long as you actually start the new process. 只要您实际启动新过程,您的代码就已经可以实现该目标。 You are missing a call to Process.Start() . 您缺少对Process.Start()的调用。

private static void RunAndExit(string command)
{
    var processInfo = new ProcessStartInfo
    {
        FileName = "cmd.exe",
        ....
    };
    Process.Start(processInfo); // add this line
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Process.Start()通过外部程序启动代码时进行调试 - Debugging when my code is started by external program with Process.Start() 从Process.Start启动时,应用程序图标为空 - Application icon is blank when started from Process.Start 获取进程的PID由Process.start()启动 - getting PID of process started by Process.start() Process.Start启动外壳,然后快速退出 - Process.Start starts a shell then quickly exits Process.Start()立即退出Windows 7 - Process.Start() exits right away on Windows 7 提示用户输入通过 Process.start() 启动的应用程序 - Prompt user for input from application started via Process.start() 为什么使用Process.Start使启动的应用程序从父应用程序位置而不是启动的应用程序的实际位置运行? - Why does using Process.Start makes the started app run from the parent app location instead of the started app's actual location? 当从 C# 中的 Process.Start 启动 cmd.exe 时,Telnet 不是可识别的命令 - Telnet is not recognized command when cmd.exe is started from Process.Start in C# 如何从Process.Start获取日志 - How to get log from Process.Start 如何从Process.Start引发FileNotFoundException - How to Throw FileNotFoundException from Process.Start
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM