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.
Process.WaitForExit Method (System.Diagnostics)Sets the period of time to wait for the associated process to exit, and blocks the current thread of execution until the time has elapsed or the process has exited.
WaitForExit() Instructs the Process component to wait indefinitely for the associated process to exit. public: void WaitForExit(); C# Copy.
You can use Process. GetProcesses() to get the currently running processes, then Process. Kill() to kill a process.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With