✅ Correct way to pass data between threads?

I have an event on a simple Winform reading from the serial port. The issue is I would like to output the data onto a winform component, but because its on an even it happens on a different thread and I get the error Cross-thread operation not valid: Control 'textBoxRecieve' accessed from a thread other than the thread it was created on.
so what is the correct way to pass this data? I know I could do something like a channel do make a cross thread communication system, but that seems excessive and I figure there is an easier way I do now know

public void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
        {
            textBoxRecieve.Text = textBoxRecieve.Text + Environment.NewLine + ((SerialPort)sender).ReadExisting();
        }

That was the function running and erroring. I was just trying to make a simple ECHO test
debugListen.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
and that is how I was setting up the event
Was this page helpful?