In VB, we can lock our code like this:
SyncLock(Me)
'Locked code
End SyncLock
Based on the following Stack Overflow information:
I’d like to have the following syntax:
SyncLock(Me, 1000) 'wait max 1000 milliseconds and then throw
'Locked code
End SyncLock
What translates to:
If Monitor.TryEnter(Me, new TimeSpan(0, 0, 0, 0, 1000))) Then
Try
//Locked code
Finally
Monitor.Exit(obj);
End Try
Else
Throw New LockTimeOutException('Could not acquire lock')
End If