Based on other questions, I'm using System.Diagnostics.Process
to Start
and Kill
a process:
this.childProcess.Kill();
this.childProcess.WaitForExit();
this.childProcess.Close();
I would assume that WaitForExit
deals with the asynchronous nature of the Kill
c开发者_开发知识库ommand, however the process in question (perl.exe) refuses to die. Instead it lingers for some period of time.
This "period of time" is causing a race condition. Is there anyway I can make sure this process actually dies?
I'm not sure what you mean by "make sure this process actually dies." Under the hood the Kill
method eventually calls TerminateProcess which is the most effective way to kill a process and WaitForExit
won't return until the process is actually gone.
The Kill
method can fail to actually kill the process in at least 2 circumstances
- You don't have sufficient rights to kill the process
- There is a debugger attached to the process (I believe this prevents TerminateProcess from working).
- Uninterruptable I/O operation (thanks Daniel)
Do either of these apply to your scenario?
精彩评论