title: Add items to listbox in C# with thread
body: <p>I want to add some items to listbox with a thread or backgroundworker in C#. But when I call <code>addlist</code> function in a loop my program is not responding for a while. How can I fix that?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>   public delegate void addToList(string st);
  
     public void addlist(string st)
     {
          if (listBox1.InvokeRequired)
          {
              listBox1.Invoke(new addToList(addlist), st);
          }
          else
          {
              listBox1.Items.Add(st);
          }
      }
  </code></pre>