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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:57:24+00:00 2026-05-20T11:57:24+00:00

Dears, I’m getting error message bellow when I try to call a sort method:

  • 0

Dears, I’m getting error message bellow when I try to call a sort method:

Error Message: Cross-thread operation not valid: Control ‘lbStart_Bubble’ accessed from a thread other than the thread it was created on.

What is here done uncorrectly!?

Thread thBubble = new Thread(new ThreadStart(bubbleSort));
thBubble.Start();


public void bubbleSort()
    {
        int row = 0, column = 0;

        start = new TimeSpan(System.DateTime.Now.Ticks);
        lbStart_Bubble.Text = start.ToString();
        this.lbStart_Bubble.Refresh();

        for(row = 1; row <= list1.Length; row++)
        {
            for(column =0; column < list1.Length-1; column++)
            {

                Thread.Sleep(delay);
                tbResult_Bubble.Clear();
                for(int i=0; i<list1.Length; i++)
                    tbResult_Bubble.AppendText(list1[i] + " " );

                if(list1[column]>list1[column+1])
                    swap(list1[column], list1[column+1], column, column+1);
            }
            display(list1);
        }

        end = new TimeSpan(System.DateTime.Now.Ticks);
        lbEnd_Bubble.Text = end.ToString();

        lbTotal_Bubble.Text = end.Subtract(start).ToString();

        tbResult_Bubble.Clear();

        for(int i=0; i<list1.Length; i++)
            tbResult_Bubble.AppendText(list1[i] + " " );

    }
  • 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-20T11:57:24+00:00Added an answer on May 20, 2026 at 11:57 am

    You cannot talk to controls from a different thread than the one that created and thus owns that control.

    So for one, your usage of the label cannot be done like that.

    Instead, you can Invoke or BeginInvoke:

    lbStart.Invoke(new Action(() =>
    {
        lbStart_Bubble.Text = start.ToString();
    }));
    

    or:

    lbStart.BeginInvoke(new Action(() =>
    {
        lbStart_Bubble.Text = start.ToString();
    }));
    

    The difference is that the first will wait until the main thread (the one that owns the label) has executed the code before it (the background thread) continues executing. Think of it has a regular method call, it just happens on a different thread.

    The second will just send off a mail to the thread that owns the label, asking it to execute the piece of code, and then not wait for it. This can be tricky to get right, for instance what if start changes in the background thread before the main thread has gotten around to executing that code?

    I would use Invoke until you get more experience with threading and then look into alternatives.

    Or, you can use BackgroundWorker which has facilities to safely send progress messages back to the main thread.

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

Sidebar

Related Questions

Dears , i was reading this post about adding the meta tags dynamically by
Dear all, I have a question about Facebook Page: ( NOT user profile page,
Dears I am working with PL-SQL and I need to define a cursor and
ma dears, i got issues more here, which could't passing structure over g_timout_add with
Dear iPhone Developers, I have an instance method which is meant to return a
Dear Expert i have the following problem when i try to get the value
Dear folks, what should I do with these error warnings that Closure Compiler outputs?
Dear Stacktoverflow, can you show me an example of how to use a QScrollBar?
Dear g++ hackers, I have the following question. When some data of an object
My application deals with e-mails coming from different sources, e.g. Outlook and IMAP mailboxes.

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.