Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7731289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:26:36+00:00 2026-06-01T06:26:36+00:00

I have DataReceviedHandler, that is reading the data from the Rx terminal. I will

  • 0

I have DataReceviedHandler, that is reading the data from the Rx terminal.
I will like to change the status of the radioButton after getting Data at Rx (from the DataReceviedHandler) but I’m getting this error: “Cross-thread operation not valid: Control ‘radioButton3’ accessed from a thread other than the thread it was created on.”
what should i do to resolve?

Thanks,
Oz

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        m_ser.GetType();
        m_ser.PortName = "COM28";
        m_ser.BaudRate = 115200;
        m_ser.Open();
        m_ser.ReadTimeout = 500;
        m_ser.WriteTimeout = 500;

    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

     public void DataReceviedHandler(object sender, SerialDataReceivedEventArgs e)
    {
        byte[] m_rxUSBbuff = new byte[500];
        SerialPort sptemp = (SerialPort)sender;
        UInt16 rxbuffLength = (UInt16)m_ser.BytesToRead;
        byte[] rxBuff = new byte[rxbuffLength];
        try
        {
            rxbuffLength = (UInt16)sptemp.Read(rxBuff, 0, sptemp.BytesToRead);
        }
        catch (System.IO.IOException)
        {
            Console.WriteLine("Faild to Read from serial InputBuffer");
            return;
        }
        int i;
        int m_rxUSBLstMsgLength;
        m_rxUSBLstMsgLength = (UInt16)rxbuffLength;
        for (i = 0; i < m_rxUSBLstMsgLength; i++)
        {
            m_rxUSBbuff[i] = rxBuff[i];
        }
        switch (m_rxUSBbuff[0])
        {
            case 1:
                radioButton1.Checked = true;
                break;
            case 2:
                radioButton2.Checked = true;
                break;
            case 4:
                radioButton3.Checked = true;
                break;
            case 8:
                radioButton4.Checked = true;
                break;
            case 16:
                radioButton5.Checked = true;
                break;
            default:
                break;
        }


    }

    private void CheckLeds_Click(object sender, EventArgs e)
    {
            byte[] txb = new byte[1] { 0xf2 };
            m_ser.Write(txb, 0, 1);
    }


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T06:26:38+00:00Added an answer on June 1, 2026 at 6:26 am

    The data arrives on a background thread and that is also where the event handler is called. You are not allowed to modify UI elements from a thread other than the one they were created on (the UI thread). If you search stackoverflow for this then you will find heaps of answers of how to do this. In Winforms you need to use InvokeRequired and in WPF you need to call the UI dispatcher.

    One of the answers in this question contains a whole bunch of links to similar questions: Cross-thread operation not valid

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have converted devise new session from erb to Haml but doens't work, this is
Have a problem that seems easy on paper but i'm having a big problem
Have a rails app that is supposed to display a list of products/managers. After
Have a n-tire web application and search often times out after 30 secs. How
Have searched the database but need to specifically sum(of hours flown or days off)in
Have a rather abstract question for you all. I'm looking at getting involved in
Have a bunch of WCF REST services hosted on Azure that access a SQL
Have a look at one of my websites: moskah.com The problem is that it
Have posting working wonderfully, and reading the response happily EXCEPT when one of the
Have a simple contact us XPage created. Have server side validation in place that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.