SafeHandle.DangerousAddRef(Boolean) 方法

定义

手动递增 SafeHandle 实例中的引用计数器。Manually increments the reference counter on SafeHandle instances.

public:
 void DangerousAddRef(bool % success);
[System.Security.SecurityCritical]
public void DangerousAddRef (ref bool success);
member this.DangerousAddRef : bool -> unit
Public Sub DangerousAddRef (ByRef success As Boolean)

参数

success
Boolean

如果成功递增引用计数器,则为 true;否则为 falsetrue if the reference counter was successfully incremented; otherwise, false.

属性

注解

DangerousAddRef 方法阻止公共语言运行时回收句柄使用的内存(在运行时调用 ReleaseHandle 方法时出现这种情况)。The DangerousAddRef method prevents the common language runtime from reclaiming memory used by a handle (which occurs when the runtime calls the ReleaseHandle method). 您可以使用此方法在 SafeHandle 实例上手动递增引用计数。You can use this method to manually increment the reference count on a SafeHandle instance. DangerousAddRef 使用 ref 参数(success)返回一个布尔值,该值指示是否已成功增加了引用计数。DangerousAddRef returns a Boolean value using a ref parameter (success) that indicates whether the reference count was incremented successfully. 这样,在发生故障的情况下,程序逻辑就可以返回。This allows your program logic to back out in case of failure. 在调用 DangerousAddRef之前,应将 success 设置为 falseYou should set success to false before calling DangerousAddRef. 如果 true``success,请通过将对 DangerousAddRef 的调用与 DangerousRelease的调用进行匹配来避免资源泄漏。If success is true, avoid resource leaks by matching the call to DangerousAddRef with a corresponding call to DangerousRelease.

注意

此方法适用于高级用户,必须始终谨慎使用。This method is intended for advanced users and must always be used carefully. 若要避免泄漏句柄资源,请始终在受约束的执行区域(CER)中调用此方法,在这种情况下,线程中止无法中断处理。To avoid leaking handle resources, always call this method inside a constrained execution region (CER), where a thread abort cannot interrupt processing.

安全性

SecurityPermission
用于调用非托管代码的权限。for permission to call unmanaged code. 安全操作: LinkDemandSecurity action: LinkDemand. 关联的枚举: UnmanagedCodeAssociated enumeration: UnmanagedCode

适用于

另请参阅