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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:06:10+00:00 2026-05-12T16:06:10+00:00

So I am writing a small Twitter client for me to use. I am

  • 0

So I am writing a small Twitter client for me to use. I am using a combination of one big panel, with smaller panels representing the individual tweets. In each smaller panel, I have a PictureBox and a RichTextBox.

Now, my problem is that loading more than 10 tweets causes a slowdown because I am dynamically generating the panels. So I decided to do this using a BackgroundWorker and then add those panels to the main panel.

I’ve done this numerous times with writing text to a textbox from a different thead(even wrote tutorials on it). Yet I cannot get this to work. I get the error message:

Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on.

Code:

List<Panel> panelList = new List<Panel>();

foreach (UserStatus friendStatus in list)
{
    PictureBox pbTweet = new PictureBox();
    // ...
    // code to set numerous properties
    // ...

    RichTextBox rtbTweet = new RichTextBox();
    // ...
    // code to set numerous properties
    // ...

   Panel panelTweet = new Panel();
    // ...
    // code to set numerous properties
    // ...

   panelTweet.Controls.Add(pbTweet);
   panelTweet.Controls.Add(rtbTweet);

   panelList.Add(panelTweet);
}

if (panelMain.InvokeRequired)
    panelMain.BeginInvoke((MethodInvoker)delegate { foreach (Panel p in panelList) { panelMain.Controls.Add(p); } });

Anybody notice any problems?

  • 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-12T16:06:10+00:00Added an answer on May 12, 2026 at 4:06 pm

    When using a background thread, you have to completely separate out the parts that retrieve data from the parts that modify the form controls. All code that modifies the form controls must be invoked on the UI thread, even if it will take some time to do. There is no way round this.

    This is normally a good strategy is because, usually, getting the data into memory is the slow part and updating the UI is the fast part (relative to each other).

    In your code example, all of the code is the UI-modification part, so it must all go in the UI thread.

    EDIT: To optimise the UI part, you could experiment with calling SuspendLayout and ResumeLayout on the panels that you are modifying.

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

Sidebar

Related Questions

I'm writing a small program (a twitter client) in Java, aimed at Mac OS
I'm writing a small sample app using Ember.js. My goal is to determine use
I am writing a small library and want to make it accessible using autotools
I'm writing a small web server in Python, using BaseHTTPServer and a custom subclass
Hi am writing small app for posting twitts on twitter.com I manage to create
I am writing small social application. One of the features is to write user
Am writing one small application to parse from XML to JSON object for iphone.
I'm writing a small PHP script to grab the latest half dozen Twitter status
I'm writing a small ruby program to play with Twitter over OAuth and have
I'm writing a small Java app using JavaMail that sends the user an automated

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.