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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:00:01+00:00 2026-06-09T16:00:01+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)
            {
                List<string> tempNamesAndTexts = new List<string>();
                if ((worker.CancellationPending == true))
                {
                    e.Cancel = true;
                    break;
                }
                else
                {



                    string content = downloadContent();
                    GetProfileNames(content);
                    GetTextFromProfile(content);
                    for (int i = 0; i < names.Count; i++)
                    {
                        tempNamesAndTexts.Add(names[i] + " " + texts[i]);
                         namesAndTexts.Add(names[i] + " " + texts[i]);
                    }
                    if (InvokeRequired)
                    {
                        bool result = tempNamesAndTexts.SequenceEqual(namesAndTexts);
                        if (result == true)
                        {
                        }
                        else
                        {
                            foreach (string com in tempNamesAndTexts)
                            {
                                if (!namesAndTexts.Contains(com))
                                {
                                    MessageBox.Show(com);
                                }
                            }


                            //BeginInvoke(new Action(() => namesAndTexts.ForEach(Item => textBox1.AppendText(Item + Environment.NewLine))));
                        }

                        
                    }
                    reader.Close();
                    response.Close();
                    Thread.Sleep(1000);
                }
            }
        }

I have a List<string> namesAndTexts in the Form1 level.
And another temp local List<string> tempNamesAndTexts

What I need to do is in DoWork I’m updating the namesAndTexts every n seconds from a websites using the two functions in the DoWork.

In the end I have the namesAndTexts List for example:

[0] Daniel hello
[1] Moses hi

I need to compare this namesAndTexts with the tempNamesAndTexts List and each time when its updating the List if they are the same don’t do anything.

But if they are not the same find what was different in the two Lists and this different part only this add to the textBox.

The problem is now that namesAndTexts all the time grow and grow 18 then 36 then 72 indexes its keeping adding the same strings over and over.


What I need to do is:

  1. Download the content from a website every n seconds (downloadContent();)

  2. Create a List of names the GetProfileNames function.

  3. Create a List of texts GetTextFromProfile function.

  4. Create a List of the two Lists in 2. and 3. with names and text together.

  5. Store the old List in 4. to remember the last update.

  6. compare the last update with the new one. Compare the List in 5. with the one in 4.

  7. If the comparison result is true identical don’t do anything.

  8. If the comparison is not identical find which indexes in both Lists are not the same and add to the textBox the strings in the List which are not the same with the other one.

So the textBox should look like something, first once adding the List to the textBox for example:

Daniel is here
Modes is there
Daniela is out

Second time after comparison if its not identical find which index/s is not identical and add only the string in this index/s to the textBox.

So now the textBox will look like:

Daniel is here
Modes is there
Daniela is out
Yaron hello

So the only change was that Yaron hell is now added to the textBox.

But I can’t figure out how to do it.
Cant make the comparison of the which indexes are not the same and take them out and add them to textBox cant figure out why one of the Lists keep growing up so in the next iterations the two lists are not identical but also there are no new indexes with names and texts to add to the textbox.

  • 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-09T16:00:03+00:00Added an answer on June 9, 2026 at 4:00 pm

    You could find added or removed items thru Exept

            var list1 = new List<string> {"a", "b"};
            var list2 = new List<string> {"a", "c"};
    
            List<string> addedItems = list2.Except(list1).ToList();
            addedItems.ForEach(x => Console.WriteLine("Added items: {0}", x));
    
            List<string> removedItems = list1.Except(list2).ToList();
            removedItems.ForEach(x => Console.WriteLine("Removed items: {0}", x));
    

    Console output:

    Added items: c
    Removed items: b
    
    • 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) {
private void SaveAsPicture_Click(object sender, RoutedEventArgs e) { WriteableBitmap bmp = new WriteableBitmap(MyUIElement, null); var
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 <
I have a button click event for continue: private void button3_Click(object sender, EventArgs e)
private void getSelectedTime(final String json){ Calendar now = Calendar.getInstance(); int year = now.get(Calendar.YEAR); int

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.