SafeHandle.DangerousAddRef(Boolean) SafeHandle.DangerousAddRef(Boolean) SafeHandle.DangerousAddRef(Boolean) SafeHandle.DangerousAddRef(Boolean) Method

定义

手动递增 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 Boolean Boolean Boolean

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

注解

方法阻止公共语言运行时回收句柄使用的内存(在运行时ReleaseHandle调用方法时出现这种情况)。 DangerousAddRefThe 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. 在调用success false 之前,应DangerousAddRef将设置为。You should set success to false before calling DangerousAddRef. 如果success DangerousAddRef DangerousReleasetrue,则通过将对的调用与的相应调用进行匹配来避免资源泄漏。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

适用于

另请参阅