The lock statement obtains a mutual exclusion lock for a given object, executes a statement, and then releases the lock
This is the syntax for the lock statement:
lock expression then statement
The expression in the lock statement header must evaluate to a reference type. It is translated like this:
System.Threading.Monitor.Enter(expression); try statement; finally System.Threading.Monitor.Exit(expression); end;
The expression is evaluated only once, and a local variable may be declared if needed, to ensure this behavior.