SpinLock(Boolean) Constructor

Definitie

Initialiseert een nieuw exemplaar van de SpinLock structuur met de optie voor het bijhouden van thread-id's om foutopsporing te verbeteren.

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

Parameters

enableThreadOwnerTracking
Boolean

Of u thread-id's wilt vastleggen en gebruiken voor foutopsporing.

Voorbeelden

In het volgende voorbeeld ziet u hoe een SpinLock kan worden gebruikt.

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

Opmerkingen

De parameterloze constructor voor SpinLock het bijhoudt van het eigendom van threads.

Van toepassing op

Zie ook