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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:56:57+00:00 2026-05-16T06:56:57+00:00

I am trying to get around a Cross Thread Exception, Invalid Object Exception. Here

  • 0

I am trying to get around a Cross Thread Exception, Invalid Object Exception. Here are the details: I have two Background worker threads (there will be lots more, but I haven’t coded them yet, I am just coding the engine for them all to run on at the moment. This is a C#, Windows Forms app. Every so often, the BGWs call UpdateUI, which does a lot of updating to the UI. The same UpdateUI is used for all threads, and so it is Locked. The performance degradation of this is so minimal, that it does not matter to me. Obviously, I am now altering the UI with a BGW, ie a different thread, and so I will get a Cross Thread Exception, and so I need to Invoke(), or BeginInvoke(), but whenever I do, somehow, all of these time-consuming processes get merged onto the same thread, and execute in order, rather than at the same time. This will be because my code is wrong, not because of any other reason. I don’t really know how to use Invoke() and BeginInvoke(), and so this is copied code from similar threads, rather than my own, but it still doesn’t work. Just looking at it, it seems very odd, and not what I would have done.

So, could you please help me correct my Invoke() code? It removes the exception, but merges them all onto one thread, but not exactly sure which one, the UI thread? Also, my UpdateUI() is very long and complex, and so ideally, I would Invoke() the entire method (basically the whole thing needs Invoking) rather than each line individually, as the blow code is doing, if possible. I repeat, this is NOT what I am using to Invoke() the method, but simply change an “Enabled” status, which is why it seems so odd.

Thank you so much in advance!

Richard

MethodInvoker method = delegate
{
    label3.Enabled = true;
};

if (InvokeRequired)
{
    BeginInvoke(method);
}
else
{
    method.Invoke();
}
  • 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-16T06:56:58+00:00Added an answer on May 16, 2026 at 6:56 am

    To make sure your UpdateUI method is executed on the GUI thread, use the following:

    public void UpdateUI() {
        if (this.InvokeRequired) {
            this.Invoke(new MethodInvoker(UpdateUI));
        } else {
            // Changes to UI are made here.
        }
    }
    

    Replace this with the reference to your form if appropriate.

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

Sidebar

Related Questions

trying to get my head around Feedzirra here. I have it all setup and
Here's a very simple example of what I'm trying to get around: class Test(object):
I'm trying to get my head around the covariance of Scala's collections. I have
I have been trying to get my head around this but it hasn't been
I have been trying to get around setting navigationitem button's width property but couldn't
I have been trying to get around this error for a day now and
Trying to get my mind around google protobuf. I found some implementation of protobuf
Trying to get my head around how to integrate fancyBox with an aspx c#
Just trying to get my head around what can happen when things go wrong
I'm trying to get my head around using CoffeeScript comprehensions as efficiently as possible.

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.