SpinLock(Boolean) Constructor

Definición

Inicializa una nueva instancia de la SpinLock estructura con la opción de realizar un seguimiento de los identificadores de subprocesos para mejorar la depuración.

public:
 SpinLock(bool enableThreadOwnerTracking);
public SpinLock(bool enableThreadOwnerTracking);
new System.Threading.SpinLock : bool -> System.Threading.SpinLock
Public Sub New (enableThreadOwnerTracking As Boolean)

Parámetros

enableThreadOwnerTracking
Boolean

Si se van a capturar y usar identificadores de subprocesos con fines de depuración.

Ejemplos

En el ejemplo siguiente se muestra cómo se puede usar un SpinLock.

// C#
public class MyType
{
    private SpinLock _spinLock = new SpinLock();

    public void DoWork()
    {
        bool lockTaken = false;
        try
        {
           _spinLock.Enter(ref lockTaken);
           // do work here protected by the lock
        }
        finally
        {
            if (lockTaken) _spinLock.Exit();
        }
    }
}
' Visual Basic

Class MyType
   Private _spinLock As New SpinLock()

   Public Sub DoWork()
      Dim lockTaken As Boolean = False
      Try
         _spinLock.Enter(lockTaken)
         ' do work here protected by the lock
      Finally
         If lockTaken Then _spinLock.Exit()
      End Try
   End Sub
End Class

Comentarios

Constructor sin parámetros para SpinLock realizar un seguimiento de la propiedad del subproceso.

Se aplica a

Consulte también