The SyncLock
statement is a statement that allows statements to be synchronized on an expression. This ensures that multiple threads of execution do not execute the same statements at the same time. The expression is evaluated once, upon entry to the block. When entering the SyncLock
block, the shared method System.CriticalSection.Enter
is called on the specified expression, which blocks until the thread of execution has an exclusive lock on the object returned by the expression. The type of the expression in a SyncLock
statement must be a reference type.
The SyncLock
block is implicitly contained by a Try
statement whose finally block calls the shared method System.CriticalSection.Exit
on the expression. This ensures the lock is freed even when an exception is thrown.
SyncLock
Expression StatementTerminatorEnd
SyncLock
StatementTerminator