How to create a Process that outlives its parent

前端 未结 3 1246
栀梦
栀梦 2020-11-30 13:35

I\'m trying to launch an external updater application for a platform that I\'ve developed. The reason I\'d like to launch this updater is because my configuration utility w

3条回答
  •  忘掉有多难
    2020-11-30 14:28

    There's no reason why a process started with Process.Start should automatically die when the launcher exits. My guess is that you're doing something odd in the updater.

    I've written an updater doing exactly this kind of thing before, and it's been fine.

    For example:

    Launcher.cs:

    using System;
    using System.Diagnostics;
    
    class Launcher
    {
        static void Main()
        {
            Console.WriteLine("Launching launchee");
            Process.Start("Launchee.exe");
            Console.WriteLine("Launched. Exiting");
        }
    }
    

    Launchee.cs:

    using System;
    using System.Threading;
    
    class Launchee
    {
        static void Main()
        {
            Console.WriteLine("       I've been launched!");
            Thread.Sleep(5000);
            Console.WriteLine("       Exiting...");
        }
    }
    

    Compile both of them, separately, and run Launcher.exe. The "launchee" process definitely lasts longer than the launcher.

提交回复
热议问题