Jon
Sun Oct 23 12:16:15 CDT 2005
Willy Denoyette [MVP] <willy.denoyette@telenet.be> wrote:
> > Okay, thanks. Resource cleanup is one thing that never seems to make
> > its way into MSDN samples. They also don't document what methods of a
> > given class use unmanaged resources.
>
> Be carefull, when calling Dispose (or Close) on a Process (closing the
> process handle) you effectively kill that process (subject to privilege
> constrainst). That means, that you should not call Dispose when enumerating
> running processesn unless you want to kill them all ;-)
I haven't seen that behaviour at all. Could you demonstrate it at all?
Here's something which seems to contradict it:
using System;
using System.Diagnostics;
public class Test
{
static void Main()
{
Process proc = Process.Start("notepad.exe");
Console.WriteLine ("Started");
Console.ReadLine();
proc.Dispose();
//proc.Kill();
Console.WriteLine("Disposed");
Console.ReadLine();
}
}
As written above, Notepad stays up.
Uncommenting the "Kill" line and commenting out the "Dispose" line, the
process terminates as expected (so there's no privilege problem there).
Dispose will close the process handle, but that doesn't kill the
process as far as I'm aware.
--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too