I am trying to pass some status from a IP call in a shared sub to a label on my form.
This is the current code that i am using:
Class Server
<STAThread()> Public Shared Sub Main()
Dim aTcpMessaging As IMessagingSystemFactory = New TcpMessagingSystemFactory()
Dim anInputChannel As IInputChannel = aTcpMessaging.CreateInputChannel(theIPforLocal & ":" & thePort)
Dim aStringMessagesFactory As IStringMessagesFactory = New StringMessagesFactory()
Dim aStringMessageReceiver As IStringMessageReceiver = aStringMessagesFactory.CreateStringMessageReceiver()
AddHandler aStringMessageReceiver.MessageReceived, AddressOf StringMessageReceived
aStringMessageReceiver.AttachInputChannel(anInputChannel)
End Sub
Private Shared Sub StringMessageReceived(ByVal sender As Object, ByVal e As StringMessageEventArgs)
LANResponse = Convert.ToString(e.Message)
Dim lanSent As String() = Nothing
Dim sep(3) As Char
Dim s As String = ""
sep(0) = "~"
'sep(1) = ","
lanSent = LANResponse.Split(sep, 2)
Dim a As New Threading.Thread(AddressOf getStatus)
a.SetApartmentState(Threading.ApartmentState.STA)
a.Start(Trim(lanSent(0)) & Trim(lanSent(1)))
End Sub
End Class
Private Shared Sub getStatus(ByVal data As Object)
lblStatus.text = ("Static: " & data)
End Sub
The error its giving me is on the line lblStatus.text = ("Static: " & data)
Error 1 Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.
Any help would be great!
David
UPDATE
After adding:
Private Sub getStatus(ByVal data As Object)
If InvokeRequired Then
Invoke(New Action(Of Object)(AddressOf getStatus), data)
Else
lblStatus.Text = ("Static: " & data)
End If
End Sub
I get this error no one line Dim a As New Threading.Thread(AddressOf getStatus)
Error 1 Overload resolution failed because no accessible 'New' can be called with these arguments: 'Public Sub New(start As System.Threading.ParameterizedThreadStart)': Reference to a non-shared member requires an object reference. 'Public Sub New(start As System.Threading.ThreadStart)': Method 'Private Sub getStatus(data As Object)' does not have a signature compatible with delegate 'Delegate Sub ThreadStart()'.