简体   繁体   中英

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. 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() .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM