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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:05:43+00:00 2026-05-28T00:05:43+00:00

I have a simple app with the usual UI thread and a background worker,

  • 0

I have a simple app with the usual UI thread and a background worker, in the background worker I need to dynamically create LinkLabels and place them in a FlowLayoutPanel. In order to do this I need to set the parent of the LinkLabel to the FlowLayoutPanel.

Here is a snippet of code I currently have, however, I get the infamous “Cross-thread operation not valid” on the line ‘l.Parent = panel;’

I’m fairly new to multithreaded operations but I thought I did the invoking correctly, but obviously not. Any Suggestions?

LinkLabel l = new LinkLabel();
if (rssFeedPanel.InvokeRequired) {
    FlowLayoutPanel panel = null;
    rssFeedPanel.Invoke(new MethodInvoker(delegate { panel = rssFeedPanel; }));
    l.Parent = panel;
}
else
    l.Parent = rssFeedPanel;
  • 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-28T00:05:44+00:00Added an answer on May 28, 2026 at 12:05 am

    You need to actually set the Parent property on the other thread.

    LinkLabel l = new LinkLabel();
    if (rssFeedPanel.InvokeRequired) {
        rssFeedPanel.Invoke(new MethodInvoker(delegate {
            l.Parent = rssFeedPanel;
        }));
    }
    else
        l.Parent = rssFeedPanel;
    

    In general, nearly any operation involving accessing the members of a UI control can only be done from the UI thread. Some obvious exceptions are Invoke, InvokeRequired, BeginInvoke, and some of the methods of the BackgroundWorker class.

    If you wish for this case, you can also use BeginInvoke instead of Invoke.

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

Sidebar

Related Questions

The usual case. I have a simple app that will allow people to upload
This is a real newbie question. I have simple app that selects a picture
I have a simple app that uses an SQL Express 2005 database. When the
I have a simple app with a full screen UIWebView. This contains HTML generated
Right so I have a simple app that consists of a calendar a Set
I'm now testing GKPeerPickerController. I have a simple app that just have a button
I have a simple iphone app that's based on the CrashLanding sample app. So
I have a simple Google App Engine app, that I wrote using ordinary strings.
I have created some simple app in Java, and 'deployed' it using Java Web
I have a simple cakephp app with table articles that has a cat_id column

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.