我有一个程序拦截来自SMS调制解调器的短信,然后它意味着从我的代码的另一个类更新主窗口上的TextBox
:
主窗口:
Class MainWindow
Public WithEvents SMScon As SMSComms
Private Delegate Sub GetDisplay(ByVal SMS As SMSMessage)
Public Sub GetFromSMSComms(SMS As SMSMessage) Handles SMScon.SMSListChanged
If tb_recievedmessages.Dispatcher.CheckAccess() Then
DisplaySMS(SMS)
Else
tb_recievedmessages.Dispatcher.BeginInvoke(DispatcherPriority.Normal, New GetDisplay(AddressOf DisplaySMS), SMS)
End If
End Sub
Private Sub DisplaySMS(ByVal SMS As SMSMessage)
Debug.WriteLine("Writing To TextBox")
tb_recievedmessages.Text() = SMS.MessageText
End Sub
End Class
在另一个班级中捕获的短信:
SMSComms.vb:
Public Class SMSComms
Public Event SMSListChanged(ByVal SMS As SMSMessage)
Private Delegate Sub GetDisplaySMSCallback(ByVal SMS As List(Of String))
Public Sub DataReceivedHandler(sender As Object, e As SerialDataReceivedEventArgs)
Dim rxString As String
Dim index As Integer
Dim newMsg As New SMSMessage
RemoveHandler SMSPort.DataReceived, AddressOf DataReceivedHandler
Thread.Sleep(100)
rxString = SMSPort.ReadExisting()
rxString = TrimCRLF(rxString)
index = NewSMSIndex(rxString)
If index > -1 Then
newMsg = ReadSMS(index)
If newMsg.Index > -1 Then
AddHandler SMSListChanged, AddressOf Main.GetFromSMSComms
RaiseEvent SMSListChanged(newMsg)
End If
End If
RemoveHandler SMSListChanged, AddressOf Main.GetFromSMSComms
AddHandler SMSPort.DataReceived, AddressOf DataReceivedHandler
End Sub
End Class
现在SMS对象从SMSComms类传递到主窗口,我使用Dispatcher.BeginInvoke()来调用主线程但是当它到达写入文本框的子对象时,文本框不会更新在主UI上。
谁能告诉我为什么?或者如何更新??