,我是串口编程的新手。有没有办法在多线程应用程序的UI线程中传递SerialPort(例如.name,COM等)属性?
我想要的是在下面的代码中类似,但我的属性设置为变量。例如(property = .name,property = .text)。这样我就可以通过调用 object.property
将其返回到UI线程Public Delegate Sub SetTextCallback(ByVal control As Control, ByVal text As String)
Public Sub SetText(ByVal control As Control, ByVal text As String)
If control.InvokeRequired Then
Dim d As New SetTextCallback(AddressOf SetText)
frmMain.Invoke(d, New Object() {control, text})
Else
control.Text = text
End If
End Sub
我想要的是这样的(在c#.Net中有相同的片段,但我不能在VB.NET中这样做):
Public Delegate Sub SetTextCallback(ByVal control As Control, ByVal prop as property, ByVal text As String)
Public Sub SetText(ByVal control As Control, byVal prop as property, ByVal text As String)
If control.InvokeRequired Then
Dim d As New SetTextCallback(AddressOf SetText)
frmMain.Invoke(d, New Object() {control, prop, text})
Else
control.prop = text
End If
End Sub
提前致谢...