How can I use Process.Start(), but have the launched process not in the same process tree as the launching process?
Consider this sample console application:
using System;
using System.Diagnostics;
using System.Threading;
internal class Program
{
private static void Main(string[] args)
{
Console.WriteLine("Starting ie...");
Process.Start("c:\Program Files\Internet Explorer\iexplore.exe", "http://www.google.com");
Console.WriteLine("Waiting for 15 seconds");
Thread.Sleep(15000);
Console.WriteLine("Exiting...");
}
}
When this program exits normally, Internet Explorer will continue to run. However, if during the 15 second sleep period you go to Task Manager and select this program and select "End Process Tree", Internet Explorer will also close.
(This is directly related to my question from earlier today that, as yet, has no replies. In Windows XP, when the screen saver process ends, it appears to end the process tree, whereas in Vista, just the screen saver process is ended.)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…