SpinLock(Boolean) Constructeur

Définition

Initialise une nouvelle instance de la SpinLock structure avec l’option permettant de suivre les ID de thread pour améliorer le débogage.

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

Paramètres

enableThreadOwnerTracking
Boolean

Indique s’il faut capturer et utiliser des ID de thread à des fins de débogage.

Exemples

L’exemple suivant montre comment utiliser 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

Remarques

Constructeur sans paramètre pour SpinLock le suivi de la propriété du thread.

S’applique à

Voir aussi