SpinLock(Boolean) Konstruktor

Definition

Initialisiert eine neue Instanz der SpinLock-Struktur mit der Option, Thread-IDs nachzuverfolgen, um das Debuggen zu vereinfachen.

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

Parameter

enableThreadOwnerTracking
Boolean

Gibt an, ob Thread-IDs zu Debugzwecken erfasst und verwendet werden.

Beispiele

Im folgenden Beispiel wird veranschaulicht, wie ein SpinLock verwendet werden kann.

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

Hinweise

Der parameterlose Konstruktor für SpinLock den Titelthreadbesitz.

Gilt für

Siehe auch