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

  • SEARCH
  • Home
  • 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 7697595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:03:15+00:00 2026-05-31T22:03:15+00:00

in my app’ i’m recieving data from serial port and save them into two

  • 0

in my app’ i’m recieving data from serial port and save them into two bool arrays.
And depends on these array i’m setting checkboxes. But checkboxes are not updating only when i change the tabs….

Here’s how i’m doin’ it(maybe there’s better way how to do it)

private void comboBoxCommunication_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    if (serialPort.IsOpen)
  {
    recieveThread.Abort();
        serialPort.Close();               
  }
  ComboBoxItem cbi = (ComboBoxItem)comboBoxCommunication.SelectedItem;
  portCommunication = cbi.Content.ToString();
  serialPort.PortName = portCommunication;
  try
  {
    serialPort.Open();
    recieveThread = new Thread(dataRecieving);
        prijmiThread.Start();                                
    checkBoxI1.IsChecked = vstupy[0] ? true : false;
    checkBoxI2.IsChecked = inputs[1] ? true : false;
    checkBoxI3.IsChecked = inputs[2] ? true : false;
    checkBoxQ2.IsChecked = outputs[3] ? true : false;                                           
  }
  catch (IOException ex)
  {
        MessageBox.Show(ex.ToString(), "Error!", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
    }
}

private void dataRecieving()
{ 
    if (serialPort.IsOpen)
  {                    
    int i = serialPort.ReadChar();
    if (i == 'A')
    {
        inputs[0] = true;
    }
        else if (i == 'a')
        {
        inputs[0] = false;
    }
    if (i == 'B')
    {
        inputs[1] = true;
    }
    else if (i == 'b')
    {
        inputs[1] = false;
    }
    if (i == 'C')
    {
        inputs[2] = true;
    }
    else if (i == 'c')
    {
        inputs[2] = false;
    }
    if (i == 'D')
    {
        outputs[0] = true;
    }
    else if (i == 'd')
    {
        outputs[0] = false;
    }                        
  }           
}
  • 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-05-31T22:03:17+00:00Added an answer on May 31, 2026 at 10:03 pm

    Assuming you are tying to launch a thread that checks the serial port and then have your GUI update in near-real time to changes that come across the serial thread you probably need to do several things.

    1. I would raise an event from the serial reading code when a checkbox changes state
    2. The GUI could subscribe to this event BUT you have to be aware of cross threading. That is you can’t let the handler of the event directly update the GUI element owned by a separate thread.
    3. So in your event handler you need to invoke the update via the owning thread.

    I wrote up a blog entry once on an idiom for handling cross threading on Winform apps.

    I’m also not sure how your inputs array is defined, but in general it’s not a good idea for two threads to be accessing shared data without some type of control mechanism. If your array is based on a data type that does atomic read/writes it might be OK but typically you want to consider what happens if one thread is in the middle of a non-atomic write when another thread either reads or writes the same data. Lots of material abounds on thread safety that you probably want to become familiar with.

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

Sidebar

Related Questions

My App needs to connect to and grab data from a MySQL database sitting
App Engine only allows you to use these formats for XMPP addresses: app-id@appspot.com anything@app-id.appspotchat.com
My app uses a WebRequest at certain points to get pages from itself. This
My app needs to build a buffer from all the selected cells on a
The app in question is already localized into a few languages, but I'm adding
My app downloads content from a server and recently I've noticed the GUI has
App crashes after execution of cellForRowAtIndexPath method of tableView It goes into: UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:]
My app needs to be able to disconnect from a server and connect to
My app has been accepted by Apple and I just downloaded the version from
My app has many controls on its surface, and more are added dynamically at

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.