Ok, so i'm new to threading, I get the concept and have seen plenty of example code which I understand. My analogy at the minute is that threading is like having employees in an office. Each one goes away and does some work at the same time and can report back as and when.
Anyway, I have made a simple program to read some data from a com port. The data is then parsed and spat out into a richtextbox. Given the volume of data this may be somewhat resource intensive at times and therefore I'd like to put this method in its own thread.
I tried this as such, using similar code to the following, but keep getting told off by VS because I'm interacting with the rtb from a thread outside of what is allowed.
Private Sub btn_Restart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Restart.Click
Call restart()
End Sub
Private Sub restart()
Dim d As myDelegate = AddressOf ReceiveSerialData
d.BeginInvoke(cmb_Com.Text, rtb_ComData, Nothing, Nothing)
End Sub
Delegate Sub myDelegate(ByVal comport As String, ByRef rtb As RichTextBox)
Sub ReceiveSerialData(ByVal comport As String, ByRef rtb As RichTextBox)
Try
Catch ex As TimeoutException
rtb.Text = "Error: Com Port read timed out."
Me.pic_Data.BackColor = Color.Red
Me.pic_Checksum.BackColor = Color.Red
btn_Restart.Enabled = True
Catch ex As Exception
rtb.Text = "something went wrong, try again."
Me.pic_Data.BackColor = Color.Red
Me.pic_Checksum.BackColor = Color.Red
btn_Restart.Enabled = True
Finally
If com IsNot Nothing Then com.Close()
Me.pic_Data.BackColor = Color.Red
Me.pic_Checksum.BackColor = Color.Red
btn_Restart.Enabled = True
End Try
End Sub
Is this easy to "transfer" the code to a thread? Any help / pointers much obliged.
Cheers