SpinLock(Boolean) Construtor

Definição

Inicializa uma nova instância da estrutura com a SpinLock opção de acompanhar IDs de thread para melhorar a depuração.

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

Se deseja capturar e usar IDs de thread para fins de depuração.

Exemplos

O exemplo a seguir demonstra como um SpinLock pode ser usado.

// 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

Comentários

O construtor sem parâmetros para SpinLock rastrear a propriedade do thread.

Aplica-se a

Confira também