Question

Is it necessary to use Process.WaitForExit after Process.Kill?
What if the calling process exits right after it calls Process.Kill?
Would this cause Process.Kill to fail?

Edit: I need to kill a process on exiting my application. At this point I do not intend to handle the situations when kill fails so it is not necessary for me to wait for the process to exit. So if calling WaitForExit is not necessary I could just skip it.

Was it helpful?

Solution

According to the documentation on MSDN (emphasis mine)

Note The Kill method executes asynchronously. After calling the Kill method, call the WaitForExit method to wait for the process to exit, or check the HasExited property to determine if the process has exited.

If you don't need to wait, of if you don't need to determine if the process actually exists, then I suppose you don't need to call WaitForExit or check HasExited.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top