我正在尝试将共享子中的 IP 呼叫中的某些状态传递给表单上的标签。
这是我正在使用的当前代码:
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
它给我的错误是在lblStatus.text = ("Static: " & data)
错误 1 如果没有类的显式实例,则无法从共享方法或共享成员初始化程序中引用类的实例成员。
任何帮助都会很棒!
大卫
更新
添加后:
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
我收到此错误 no one line Dim a As New Threading.Thread(AddressOf getStatus)
错误 1 重载解析失败,因为无法使用以下参数调用可访问的“New”:“Public Sub New(start As System.Threading.ParameterizedThreadStart)”:对非共享成员的引用需要对象引用。“Public Sub New(start As System.Threading.ThreadStart)”:方法“Private Sub getStatus(data As Object)”没有与委托“Delegate Sub ThreadStart()”兼容的签名。