开发者

How often are process handles reused

I note an applications handle when I use the shell function to open it. I then use that handle to close the application later. However the user can also close that other 开发者_运维百科application himself. Can that handle then be reused by windows so that when I use that handle I close a different process. If it is possible is it likely?


No, you don't have to worry about it. The handle returned by, say, OpenProcess, ShellExecuteEx() or CreateProcess keeps the process object alive. That's how it is possible to call GetExitCodeProcess() to retrieve the exit code after the process is terminated.

The object doesn't get released until the last handle on it is closed. Opposite of earlier advice given in this thread, it is very important that you call CloseHandle() or you'll have a leak.


You can wait on a process handle to figure out when it is exited.

WaitForSingleObject(hProcess, INFINITE);

Once this returns, you know the process has exited and you don't need to close it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜