Mika M wrote:
Armin Zingler wrote:
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_fxmclictl/html/138f38b6-1099-4fd5-910c-390b41cbad35.htm
...says "You can disable this exception by setting the value of the
CheckForIllegalCrossThreadCalls property to false. This causes your
control to run the same way as it would run under Visual Studio
2003. "
I'd like to try setting this property to false, but I don't
understand where in the code and how?
..and why? If you set it to false, you'll get unpredictable results.
The topic you quoted describes this very well.
I have made my own class for reading serialport equipment. When
serialport receives data, data is saved into public property like...
Public Event ReaderDataReceived As EventHandler
Private _ReaderData As String = ""
Public Property ReaderData() As String
Get
Return _ReaderData
End Get
Set(ByVal Value As String)
...
_ReaderData = Value
...
RaiseEvent ReaderDataReceived(Me, New EventArgs)
End Set
End Property
Private Sub port_DataReceived(...) Handles port.DataReceived
'// "port" is instance of Framework 2.0 SerialPort
...
Me.ReaderData = port.ReadExisting
...
End Sub
This ReaderData-property is DataBound into Windows Form TextBox like...
txtReaderData.DataBindings.Add("Text", MyClass, "ReaderData")
and it seems not to work without setting
Control.CheckForIllegalCrossThreadCalls = False
Yes I understand it's question about unsafe threads. Handling threads is
something new for me, and this application has both class for handling
serialport and Windows Form for using class as DataBound way. I can't
figure out how to make my applicaton thread safe in this case.
I'm still trying to solve this like this way...
Public Class MyUIForm
Inherits Form
Delegate Sub SetTextCallback([text] As String)
Private Sub DisplayText(ByVal [text] As String)
' InvokeRequired required compares the thread ID of the
' calling thread to the thread ID of the creating thread.
' If these threads are different, it returns true.
If Me.txtReaderData.InvokeRequired Then
Dim d As New SetTextCallback(AddressOf DisplayText)
Me.Invoke(d, New Object() {[text]})
Else
Me.txtReaderData.Text += [text]
End If
End Sub
....but I don't know how to do binding with txtReaderData-TextBox of the
SerialPort reading-classes "ReaderData"-public property. Propably I
should not use txtReaderData.DataBindings.Add("Text", MyClass,
"ReaderData") any more, but how txtReaderData can notice when
"ReaderData"-property value changes?
That how to sample code
(ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_fxmclictl/html/138f38b6-1099-4fd5-910c-390b41cbad35.htm)
is simply too complex to figure out for someone - read: for me :) - who
is not yet familiar with threads handling in my mind.