You're right. If this is undesirable, consider that:
lock(objectLock) {
It is equivalent to:
Monitor.Enter(objectLock); try { //do something } finally { Monitor.Exit(objectLock); }
You can replace this as follows:
if(Monitor.TryEnter(objectLock, 250))
It is also worth looking at TryEnter() overloads and other synchronization objects such as ReaderWriterLockSlim .
Jon hanna
source share