SpinLock(Boolean) Konstruktor

Definition

Initialisiert eine neue Instanz der SpinLock Struktur mit der Option zum Nachverfolgen von Thread-IDs, um das Debuggen zu verbessern.

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 für Debuggingzwecke erfasst und verwendet werden sollen.

Beispiele

Das folgende Beispiel 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 die Verfolgung des Threadbesitzes.

Gilt für:

Weitere Informationen