I am writing a class called Field which uses a serial object to get some values from an Arduino. I have an event being raised by the class (when data is received from the serial port, more or less) and when that happens I need to retrieve data from this class. The code below works, but doesn't seem to do so in the way I need it to. My knowledge of just how threading works is little to none, I just know that the serial port object runs in its own thread which makes working with it a massive pain.
Private Sub Field_eScore() Handles Field.eScore
If InvokeRequired Then
Invoke(Sub() lbl_COM_data.Text = Field.GetComData())
Else
lbl_COM_data.Text = Field.GetComData()
End If
End Sub
Is there a way to easily access data operating in this other thread that doesn't involve having these “InvokeRequired” If-Then conditionals? Some more information on just how threading works in this case would be awesome too.