Hi,
What problem are you having?
Are you having trouble marshalling data to the STAThread of a form? If you
attempt to update the UI directly from an event handler, the thread context
is wrong, and things proceed badly. You have to Invoke a delegate that
exectutes in the STAThread context. It is common to use Control.Invoke, but
I prefer Me.Invoke (or this, perhaps). You cannot pass data into this
delegate, because of the limited threading model that the Compact Framework
provides. So, you have to use some form of shared data (Private, for
example).
Here is code that I use for handling an OnComm event that is generated by
the ReadThread in my serial class:
Private Sub ReceiveEvent() Handles SerialPort.OnComm
ScreenBuff.Append(SerialPort.InputString)
'This is FAR from the best way to display (or manage) this data. It is
"quick and dirty."
Me.Invoke(New EventHandler(AddressOf DisplayData))
End If
End Sub
Private Sub DisplayData(ByVal sender As Object, ByVal e As EventArgs)
'This marshals receive data from the receive thread context (OnComm or
CommError) to the Windows Form STAThread context
With txtTerm
..Text = ScreenBuff.ToString
..SelectionStart = .Text.Length
If (ErrorMessage.Length > 0) Then
..SelectedText = ErrorMessage
ErrorMessage = ""
End If
End With
With ScreenBuff
If .Length > 0.8 * .Capacity Then
ScreenBuff.Remove(0, CInt(0.6 * .Capacity))
End If
End With
End Sub
Dick
--
Richard Grier (Microsoft Visual Basic MVP)
See
www.hardandsoftware.net for contact information.
Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.