[英]Does Process.Kill release resources such as a handle on a file?
我有下面的代码:
proc.Start(); // "proc" opens "foo.txt" and reads it.
proc.Kill();
proc.WaitForExit();
cleanup(); // deletes "foo.txt"
我收到一个异常消息,告诉我“ foo.txt”正在被另一个进程使用。 可能会使用“ foo.txt”的唯一进程是“ proc”,我已杀死它并等待其退出。
Process.Kill是否不释放被终止进程的资源? 如果是这样,我该如何释放被终止进程持有的资源,以便清理。
谢谢。
你可以这样做:
do
{
//wait for process to exit
}while (!myProcess.WaitForExit(1000)); //milliseconds to wait for exit
cleanup();
在这里也可以看看WaitForExit MSDN
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.