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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:18:37+00:00 2026-06-09T13:18:37+00:00

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; while

  • 0
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) 
{
    BackgroundWorker worker = sender as BackgroundWorker;
    while (true)
    {

        if ((worker.CancellationPending == true))
        {
            e.Cancel = true;
            break;
        }
        else
        {



            string content = downloadContent();
            GetProfileNames(content);
            GetTextFromProfile(content);
            for (int i = 0; i < names.Count; i++)
            {
                 namesAndTexts.Add(names[i] + " " + texts[i]);
            }
            if (InvokeRequired)
            {
                for (int f = 0; f < namesAndTexts.Count -1; f++)
                {
                    BeginInvoke(new Action(() => textBox1.AppendText(namesAndTexts[f])), null);
                }
            }
            reader.Close();
            response.Close();
            Thread.Sleep(1000);
        }
    }
}

I tried this part:

if (InvokeRequired)
{
    for (int f = 0; f < namesAndTexts.Count -1; f++)
    {
        BeginInvoke(new Action(() => textBox1.AppendText(namesAndTexts[f])), null);
    }
}

But its not working good its keeping adding the list over and over to the textBox.
I want in the textbox to see it as:

daniel hello

yaron bye

danny good

And only once.

Another thing is if in the For im not doing namesAndTexts.Count - 1 but namesAndTexts.Count then its throwing me error exception the namesAndTexts[f] that the index should not be less then zero but less then the list….


After this will work I need to check if the List is changed and make somehow automatic push up in the textBox lets say to fill the textBox to its size with lines and when its getting to the bottom start scroll up and keep update the new lines only from the bottom abnd push the old ones up from the top.

How can i do it?

  • 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-06-09T13:18:39+00:00Added an answer on June 9, 2026 at 1:18 pm

    Replace these lines:

    for (int f = 0; f < namesAndTexts.Count -1; f++)
    {
         BeginInvoke(new Action(() => textBox1.AppendText(namesAndTexts[f])), null);
    }
    

    with these:

    textBox1.Clear();
    namesAndTexts.ForEach(Item=> textBox1.AppendText(Item + Environment.NewLine));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; while
I have this code : private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker
This is the code: private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker =
Let's say I have a background worker like this: private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs
I use a BackgroundWorker and do this: private void loadNewAsyncToolStripMenuItem_Click(object sender, EventArgs e) {
I got the following code: string path = Environment.CurrentDirectory; private void button1_Click(object sender, EventArgs
private void button1_Click(object sender, EventArgs e) { for (int i = 0; i <
private void SaveAsPicture_Click(object sender, RoutedEventArgs e) { WriteableBitmap bmp = new WriteableBitmap(MyUIElement, null); var
WinForms application, with one background worker, do some stuff and nothing else: private void
I have a button click event for continue: private void button3_Click(object sender, EventArgs e)

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.