Fred,
I don't have links handy, however I have seen numerous recommendations that
you should NOT use Me.GetType to lock on, that instead you should create an
explicit "padlock" variable. The biggest reason being is you may lock on
Me.GetType for one reason, while another section of code my attempt to lock
on Me.GetType for a different reason and you actually introduced a deadlock!
Also Me.GetType is not instance sensitive. All instances of the class will
block on the type, which most of the time you only need to lock on the class
instance...
The easiest way to create a "padlock" is a new object, literally "new
object"
private readonly m_padlock As New Object()
Sub SomeWork()
SyncLock m_padlock
...Code here
End SyncLock
End Sub
You can make m_padlock Shared if you need it to be across instances, however
IMHO most of the time you do not need Shared padlocks, as you want each
instance of a class to be able to run on its own thread.
Hope this helps
Jay
"fred" <So***@NoSpam.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... If I have multiple threads running a Sub as below then a number of threads
can be held up at the SyncLock. When it becomes free which thread goes
first. Is it just by chance which thread goes first or do the threads
queue in a FIFO or perhaps a LIFO bases.
Thanks
Fred
Sub SomeWork()
SyncLock Me.GetType
...Code here
End SyncLock
End Sub