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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:02:56+00:00 2026-05-31T16:02:56+00:00

I use a BackgroundWorker and do this: private void loadNewAsyncToolStripMenuItem_Click(object sender, EventArgs e) {

  • 0

I use a BackgroundWorker and do this:

private void loadNewAsyncToolStripMenuItem_Click(object sender, EventArgs e)
{
    this.Text = "RunWorkerAsync()";
    backgroundWorkerLoading.RunWorkerAsync();
}
private void backgroundWorkerLoading_DoWork(object sender, DoWorkEventArgs e)
{
    UnsafeThreadMethod("hello");
    EvenUnsaferThreadMethod();
}

And now the two methods.

private void UnsafeThreadMethod(string text)
{
    toolStripLabelRssFeedData.Text = text;
}

private void EvenUnsaferThreadMethod()
{
    panelLoading.Visible = true;
}

I don’t understand why UnsafeThreadMethod doesn’t throw the following exception but EvenUnsaferThreadMethod does.

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

According to the message it’s because toolStripLabelRssFeedData was created on the same thread but it wasn’t.

I thought that I can’t call controls created by the main thread and have to use the ProgressChanged event. What’s going on?

And I have a second question. What is the advantage of doing it like this when I can use ProgressChanged? What should I do?

private void EvenUnsaferThreadMethod()
{
    if (panelLoading.InvokeRequired)
    {
        panelLoading.Invoke(new MethodInvoker(() => { EvenUnsaferThreadMethod(); }));
    }
    else
    {
        panelLoading.Visible = true;
    }
}
  • 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-31T16:02:57+00:00Added an answer on May 31, 2026 at 4:02 pm

    To the first question:

    • the cross-thread exception is deliberately thrown in Debug mode. This means there is (conditional) code checking on InvokeRequired built into most of the GUI controls. Like the Panel.

    • Apparently the ToolstripLabel does not make this check. Since it does not derive from Control that could be because it is outside the scope of this safety net.

    Since the standard disclaimer “Any instance members are not guaranteed to be thread safe” applies to the ToolstripLabel I would just go with the normal InvokeRequired logic when setting the Text.

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

Sidebar

Related Questions

i'm loading screen in backgroundworker: private void LSLoadingScreen(object sender, DoWorkEventArgs e) { LoadingScreen ls
For instance, a thread that is a BackgroundWorker, can be cast like: private void
I have been at work this afternoon trying to use a backgroundworker to read
QUESTION: Re use of .NET Backgroundworker, is there not a way to let exceptions
I have a multi-step BackgroundWorker process. I use a marquee progress bar because several
use this website a lot but first time posting. My program creates a number
Use case: I've just entered insert mode, and typed some text. Now I want
i'm developing a twitter client in WPF and i want to use a backgroundworker
Using C# .NET 4.0 I am trying to use a BackgroundWorker to retrieve a
I use BackgroundWorker most of the time in the win form apps to show

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.