处置RegistryKey也会将其关闭吗? [英] Will disposing a RegistryKey also close it?
问题描述
正如标题所述.
另外,反之亦然.将关闭RegistryKey进行处理吗?
我浏览了所有可以找到的文档,并且在任何地方都没有提及.
它将在 Close()
内部调用 Dispose()
方法,表示是将会是"已处置
",而围绕 Dispose()
的其他方式将是 Close()
key
.系统注册表项永远不会关闭
.仅已关闭
的键
- HKEY_PERFORMANCE_DATA
.
.net的 Close
方法的源代码:
/***关闭此键,如果内容已修改,则将其刷新到磁盘.*/public void Close(){处置(true);}
.Dispose 方法的
.NET源:
[System.Security.SecuritySafeCritical]//自动生成私人空白Dispose(布尔处置){如果(hkey!= null){如果(!IsSystemKey()){尝试 {hkey.Dispose();}捕获(IOException){//现在我们并不在乎句柄是否无效}最后{hkey = null;}}否则if(dispose&& IsPerfDataKey()){SafeRegistryHandle.RegCloseKey(RegistryKey.HKEY_PERFORMANCE_DATA);}}}
As the title says.
Also, the other way around; will closing a RegistryKey dispose it?
I've looked around in all documentation I could find and nothing of this is mentioned anywhere.
It will call the Dispose()
method inside of Close()
, meaning YES it will be "disposed
" and other way around Dispose()
will Close()
key
. System registry keys are never closed
. Only keys
that are being closed
- HKEY_PERFORMANCE_DATA
.
.NET source for Close
method:
/**
* Closes this key, flushes it to disk if the contents have been modified.
*/
public void Close() {
Dispose(true);
}
.NET source for Dispose
method:
[System.Security.SecuritySafeCritical] // auto-generated
private void Dispose(bool disposing) {
if (hkey != null) {
if (!IsSystemKey()) {
try {
hkey.Dispose();
}
catch (IOException){
// we don't really care if the handle is invalid at this point
}
finally
{
hkey = null;
}
}
else if (disposing && IsPerfDataKey()) {
SafeRegistryHandle.RegCloseKey(RegistryKey.HKEY_PERFORMANCE_DATA);
}
}
}
这篇关于处置RegistryKey也会将其关闭吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!