Does Process.HasExited return erroneous values?

Process p =new Process();
p.StartInfo.FileName = "cmd.exe";

for
(int i = 0; i < 1000; i++) {
p.Start();
p.Kill();
if(p.HasExited) {
Console.WriteLine("PROCESSEXITED on Kill");
}else {
Console.WriteLine("FAILURE on Kill");
}
}

When I execute the above block of code I see "FAILURE on Kill" being printed always. However, if I replace the "cmd.exe" with "notepad.exe", then I see "PROCESSEXITED on Kill" being displayed.

Anybody can make out head or tail of this?

[922 byte] By [kishore_vinod] at [2008-1-19]
# 1
And when you try this:

Process p = new Process();
p.StartInfo.FileName = "cmd.exe";

for
(int i = 0; i < 1000; i++) {
p.Start();
p.Kill();
p.WaitForExit();
if(p.HasExited) {
Console.WriteLine("PROCESSEXITED on Kill");
}else {
Console.WriteLine("FAILURE on Kill");
}
}

Because it can take a shot time before the process is really killed.

Questa at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified