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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:50:57+00:00 2026-06-17T04:50:57+00:00

I have a problem when reading a String list, here is my code. public

  • 0

I have a problem when reading a String list, here is my code.

public partial class form : Form
{
    public static List<String> errores = new List<String>();

   private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e){

        BackgroundWorker bw = sender as BackgroundWorker;

        // Extract the argument. 
        string arg = (string)e.Argument;

        // Start the time-consuming operation.
        //  e.Result =
        if (tags.prog2(arg) == false)
        {
            //guardar en lista de no completadas
            form.errores.Add("a");

        }
  //some code here
        }




    private void buscar()
    {

    //Some code here
        foreach (string i in rutas)
            {
                backgroundWorker1 = new System.ComponentModel.BackgroundWorker();

                backgroundWorker1.WorkerSupportsCancellation = true;
                backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork);
                backgroundWorker1.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.backgroundWorker1_RunWorkerCompleted);
                backgroundWorker1.RunWorkerAsync(i);                    


            }
          foreach (string prime in form.errores)
            {
                MessageBox.Show(prime);
            }
    }
}

but there is no elements in the list, why its happening this?

Obviously I call both functions

Aclaration
function1 its a backgroundWorker, so its called too many times, I dont know if this is related to the error.

  • 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-17T04:50:58+00:00Added an answer on June 17, 2026 at 4:50 am

    Aclaration function1 its a backgroundWorker, so its called too many times, I dont know if this is related to the error

    Seems read() is called before function1() call. As function1 is called by BackgroundWorker it is quite possible.

    You should keep a flag to indicate whether function1 is called or not. If not called, you should take preventive action.

    For the reference, following code is running well (and producing "aaa" output)

    form f = new form(); 
    f.Test();
    

    public partial class form 
    {
        public static List<String> errores = new List<String>();
    
        private void function1()
        {
            form.errores.Add("aaa");
        }
    
        //Now I try to read it in other function.
    
        private void read()
        {
            foreach (string i in form.errores)
            {
                Console.WriteLine(i);
            }
        }
    
        public void Test()
        {
           function1();
           read();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a java class like this public class A { private String field1;
I have a problem reading uploaded XML file to the string instead of file.
I have a problem reading a txt file to insert in the mysql db
Android 2.1 update 1 Eclipse 3.5 I have a problem reading data from my
I have a problem with reading some gml files in c#. My files do
I have some problem with reading from sqlite3 database. -(void) readMessengesFromDatabase { sqlite3 *database;
In my assignment i have a problem with reading a file. See the following
i have one problem controlling checkbox, i'm reading, and searching about the topic but
i have been reading about multiple inheritance What is the exact problem with multiple
My problem involves checking if I have a valid database connection before reading from

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.