Compartir a través de


Método SafeHandle.DangerousAddRef (Boolean)

 

Publicado: noviembre de 2016

Incrementa manualmente el contador de referencia de las instancias SafeHandle.

Espacio de nombres:   System.Runtime.InteropServices
Ensamblado:  mscorlib (en mscorlib.dll)

Sintaxis

[SecurityCriticalAttribute]
public void DangerousAddRef(
    ref bool success
)
public:
[SecurityCriticalAttribute]
void DangerousAddRef(
    bool% success
)
[<SecurityCriticalAttribute>]
member DangerousAddRef : 
        success:bool byref -> unit
<SecurityCriticalAttribute>
Public Sub DangerousAddRef (
    ByRef success As Boolean
)

Parámetros

  • success
    Type: System.Boolean

    true si el contador de referencia se incrementó correctamente; en caso contrario, false.

Comentarios

The M:System.Runtime.InteropServices.SafeHandle.DangerousAddRef(System.Boolean@) method prevents the common language runtime from reclaiming memory used by a handle (which occurs when the runtime calls the M:System.Runtime.InteropServices.SafeHandle.ReleaseHandle method). You can use this method to manually increment the reference count on a T:System.Runtime.InteropServices.SafeHandle instance. M:System.Runtime.InteropServices.SafeHandle.DangerousAddRef(System.Boolean@) 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. You should set success to false before calling M:System.Runtime.InteropServices.SafeHandle.DangerousAddRef(System.Boolean@). If success is true, avoid resource leaks by matching the call to M:System.Runtime.InteropServices.SafeHandle.DangerousAddRef(System.Boolean@) with a corresponding call to M:System.Runtime.InteropServices.SafeHandle.DangerousRelease.

Advertencia

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.

Seguridad

SecurityPermission

for permission to call unmanaged code. Security action: F:System.Security.Permissions.SecurityAction.LinkDemand. Associated enumeration: F:System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode

Información de versión

Plataforma universal de Windows
Disponible desde 8
.NET Framework
Disponible desde 2.0
Biblioteca de clases portable
Se admite en: plataformas portátiles de .NET
Silverlight
Disponible desde 2.0
Windows Phone Silverlight
Disponible desde 7.0
Windows Phone
Disponible desde 8.1

Ver también

DangerousRelease
Clase SafeHandle
Espacio de nombres System.Runtime.InteropServices

Volver al principio