So we are working the MVP design patterns in VB.net. We have a simple Logon View and Interface:
Public Interface ILogonView
ReadOnly Property Username() As String
End Interface
Public Class LogonView
Implements ILogonView
Public ReadOnly Propery Username As String Implements ILogonView.Username
Get
tbUsername.Text
End Get
End Property
End Class
The trouble is that we need to modify the Get so that it is thread-safe. Doing so means we need to optionally wrap the code in a Control.Invoke()
call to ensure we only access UI objects from the main thread.
For example, if instead of doing this with a Property, we instead did this with a standard getter, we'd use recursion. Something like:
Function GetUsername() as String
If Me.InvokeRequired Then
Return Me.Invoke(Sub() GetUsername())
End If
Return tbUsername.Text
End Function
My question is -- can we call a Property recursively from within the property's Getter? My Vb.net is a bit rusty, and I can't discover the syntax magic to accomplish this.