SpinLock(Boolean) Construtor
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Inicializa uma nova instância da SpinLock estrutura com a opção de rastrear 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 deve capturar e usar IDs de thread para fins de depuração.
Exemplos
O exemplo seguinte demonstra como um SpinLock pode ser utilizado.
// 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
Observações
O construtor sem parâmetros para SpinLock a propriedade do thread track.