I have data being read from a UDP port in another thread. I start the UDP client using a Task, and raise the event when a certain criteria is met. The event is subscribed within my button thread. But when I try to update my label, it gives an error that "lblHeartbeat" accessed from a thread other than the thread it was created on. Isn't it now within the correct thread?
within my UI, I have:
private void btnMyButton_Click(object sender, EventArgs e)
{
Task.Factory.StartNew(() => SetName(obj1, obj2, obj3));
myListiner.MessageReceived += (s) => lblHeartRate.Text = s;
}
public void SetName(object obj1, object obj2, object obj3)
{
myListiner.SpreadValue(obj1, obj2, obj3);
}