When you call .WaitForExit()
your current process waits until the external application is closed. There is no point in calling .Kill()
afterwards, because the process is already gone. A simple example:
var p = new Process
{
StartInfo =
{
FileName = "cmd.exe"
}
};
p.Start();
Console.WriteLine("press any key to kill the other app");
Console.ReadKey();
if (!p.HasExited)
{
p.Kill();
Console.WriteLine("other app was killed");
}
else
{
Console.WriteLine("other app was already dead");
}
Console.ReadKey();
Depending on what you want, you may as well just skip the call to .Kill()
in your current code - as I've mentioned, the external process is already gone after .WaitForExit()
.