I have a property getter with a lock like this one:
Public ReadOnly Property ActiveClientList() as List(Of TcpClient)
Get
SyncLock(m_activeClientListLock)
Return m_activeClientList
End SyncLock
End Get
End Property
When I do a ForEach loop when is the property getted? I mean, in this loop when the list is locked? At the first check? On each iteration? At the whole loop?
For Each client as TcpClient in Me.ActiveClientList
Next
Thanks in advance!
For Eachis actually syntactic sugar. The compiler expands it to this:Apologies if this isn’t true VB.NET (I’m a C# boy).
As you can see, the call to
ActiveClientListhappens once, right at the start of the loop.