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 8132907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:27:33+00:00 2026-06-06T09:27:33+00:00

i have a code which is like this : private void testToolStripMenuItem_Click(object sender, EventArgs

  • 0

i have a code which is like this :

private void testToolStripMenuItem_Click(object sender, EventArgs e)
{
    toolStripStatusLabel1.Text = " Device Testing...";

    positive = false;

    clearsensors_gui();
    datarec = false;
    cmd = 04;
    datarec = serialport_FT(0, 1);

    if (datarec)
    {
        char ab = Convert.ToChar(rec_data[1]);
        //MessageBox.Show("\n" + ab + "\n");
        int cab = Convert.ToInt16(ab);
        int cabc1 = cab & 1;
        int cabc2 = cab & 2;
        int cabc3 = cab & 4;
        int cabc4 = cab & 8;
        int cabc5 = cab & 16;
        int cabc6 = cab & 32;

        if (cabc1 == 1)
            ovalShape1.FillColor = Color.Green;
        else
            ovalShape1.FillColor = Color.Red;

        if (cabc2 == 2)
            ovalShape2.FillColor = Color.Green;
        else
            ovalShape2.FillColor = Color.Red;

        if (cabc3 == 4)
            ovalShape3.FillColor = Color.Green;
        else
            ovalShape3.FillColor = Color.Red;

        if (cabc4 == 8)
            ovalShape4.FillColor = Color.Green;
        else
            ovalShape4.FillColor = Color.Red;

        if (cabc5 == 16)
            ovalShape5.FillColor = Color.Green;
        else
            ovalShape5.FillColor = Color.Red;

        if (cabc6 == 32)
            ovalShape6.FillColor = Color.Green;
        else
            ovalShape6.FillColor = Color.Red;

        toolStripStatusLabel1.Text = " Device Tested";
    }
    else
    {
        toolStripStatusLabel1.Text = "Try Again or Communication With Device Failure....";
    }
}

the above code is to read a the sensors i.e datarec = serialport_FT(0, 1); function provides me a sensor output at the GUI side which’ll be later depicted with red\green ovalShapeX(1-6)

Question: datarec = serialport_FT(0, 1); this function takes liltime and so the GUI freezes till that time how to avoid this?

i tried using background worker but didn’t get where to put this whole process
also encountered with cross-threaded operation error when it goes to ovalShape and changing its properties.

I’m not getting what part of the function to be used in the background and where and when to get back to the 1st thread

please help me to use backgroundworker or use invoke if i have to use Threading

  • 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-06T09:27:34+00:00Added an answer on June 6, 2026 at 9:27 am

    You could do something like this:

    toolStripStatusLabel1.Text = " Device Testing...";
    positive = false;
    clearsensors_gui();
    datarec = false;
    cmd = 04;
    
    BackgroundWorker worker = new BackgroundWorker();
    
    worker.DoWork += delegate(object s, DoWorkEventArgs args)
    {
        // Will be run on background thread
        args.Result = serialport_FT(0, 1);
    };
    
    worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
    {
        bool result = (bool)args.Result;
    
        if (result)
        {
            // Do your UI updates here
        }
    };
    
    worker.RunWorkerAsync();
    

    One improvement could be to combine datarec and rec_data as a Tuple in args.Result.

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

Sidebar

Related Questions

I have this code: 001 private void uiButton1_Click(object sender, EventArgs e) 002 { 003
I have code like this: private var video:Video; ... private function init():void { ...
I have jQuery code which looks something like this on Button1 Click $('table.result_grid tbody
I have code which needs to do something like this There is a list
I have some Java code which looks roughly like this: String urlString = ftp://polar.ncep.noaa.gov/pub/history/waves/multi_1.glo_30m.dp.200601.grb2;
I have a code like this, which is solved by me following a exercise
I have a code like this below, which gives me a $link that equals
I'm training code problems like UvA and I have this one in which I
I have code which looks like: private static DirectiveNode CreateInstance(Type nodeType, DirectiveInfo info) {
I have a code sample which look something like this. public class AdventureWorksRepository {

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.