在循环中对物理设备路径调用 CreateFile
我有一些 C# 代码,每次通过 pInvoke 循环(即 \.\PhysicalDrive1,然后 \.\PhysicalDrive2,...)在不同的物理设备路径上调用 CreateFile,然后使用返回的句柄执行其他一些低级别操作窗户的东西。在循环结束时,它对句柄调用 CloseHandle。
在调试时,我注意到每次循环时句柄的 int 值都是相同的。我可以看到这要么是预期的(Windows 只是重用句柄),要么是意外的(上次传递句柄没有释放)。
所以我只想验证这是否是预期的(或者至少不是不正确的)行为。
I have some C# code that is calling CreateFile on a different physical device path each time through a loop(ie \.\PhysicalDrive1, then \.\PhysicalDrive2, ...) via pInvoke and then using the returned handle do some other low level windows stuff. At the end of the loop it calls CloseHandle on the handle.
While debugging I noticed that the int value of the handle was the same each pass through the loop. I can see this being either expected (windows is just reusing the handle) or unexpected (the handle wasn't released last pass).
So I just want to verify whether or not this is expected (or at least not incorrect) behaviour.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
句柄只是内核中某个表中某个条目的索引。如果您重复打开和关闭句柄,则它完全有可能获得表中完全相同的条目,从而获得相同的索引。
请注意,这是特定于实现的,并且可能会随着任何新版本、服务包或 QFE 的变化而改变。
A handle is just an index to some entry into some table in the kernel. If you are opening and closing a handle repeatedly, it is entirely possible for it to get the exact same entry in the table and hence the same index.
Be aware that this is implementation specific and can change with any new release, service pack, or QFE.