Lock([LockName As String = ""] [, TimeoutMs = -1]) As LockObject
The Lock functions returns a Lock object. Once the Lock object is returned, the code does have that lock. The LockName can be used to create a Lock that can be used at multiple locations in your code (by using the same name). If you do not want to wait infinitely, you can specify the TimeoutMs. In that case, if the time expired an no lock was obtained, an error will be raised.
Always make sure to dispose of the lock after use to prevent deadlocks. Best practice is to use the Lock in a Using-statement:
Using Lock
'Do some actions that can't have interference
End Using