System.Runtime.InteropServices.SafeHandle.DangerousRelease Method

Manually decrements the reference counter on a System.Runtime.InteropServices.SafeHandle instance.

Syntax

[System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)]
public void DangerousRelease ()

Remarks

The SafeHandle.DangerousRelease method is the counterpart to SafeHandle.DangerousAddRef(Boolean@). You should always match a call to the SafeHandle.DangerousRelease method with a successful call to SafeHandle.DangerousAddRef(Boolean@).

Note:

This method is intended for advanced users and must always be used carefully. To avoid leaking handle resources, always call this method inside a constrained execution region (CER), where a thread abort cannot interrupt processing. In the same way that unmatched SafeHandle.DangerousAddRef(Boolean@) calls can cause resource leaks, unmatched SafeHandle.DangerousRelease calls can cause invalid handle states to become visible to other threads. Do not expose SafeHandle.DangerousAddRef(Boolean@) or SafeHandle.DangerousRelease calls to untrusted code.

Requirements

Namespace: System.Runtime.InteropServices
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: