产生新的进程会杀死它的父进程但进程仍然活着?

时间:2013-10-10 06:53:17

标签: c# multithreading

我有一个服务正在运行,该服务将创建一个新线程来启动一个进程。

它启动的过程将调用一个MSI,它将基本上停止原始父服务(调用启动msi的进程的服务)

截至目前,该过程终止,导致MSI在完成执行之前失败。

startInfo.FileName = "UpdateInstaller.exe";
startInfo.Arguments = "ParentServiceName.exe";
startInfo.UseShellExecute = true;
startInfo.RedirectStandardOutput = false; //Edited as per comment below. Still wont work 

new Thread(() =>
{
    Thread.CurrentThread.IsBackground = true;
    Process.Start(startInfo);
}).Start();

关于如何运行此过程但是保持活着的任何想法,即使在父母去世后也是如此?

1 个答案:

答案 0 :(得分:0)

在调用代码终止后,代码启动的此过程将保持打开状态。一个很好的例子 - 如果你有一个自然会在这里退出的控制台应用程序,记事本过程将在“消失后”保持打开状态:

    static void Main(string[] args)
    {
        var startInfo = new ProcessStartInfo
        {
            FileName = "notepad.exe",
            UseShellExecute = true,
            RedirectStandardOutput = false
        };

        new Thread(() =>
        {
            Thread.CurrentThread.IsBackground = true;
            Process.Start(startInfo);
        }).Start();
    }