This question has already been answered:
- Work with controls from background thread 2 responses
You need to run N number of parallel streams and output the data to the form ( ListBox ) interactively from them. This is approximately what happens:
public partial class Form1 : Form { public Form1() { InitializeComponent(); } private string name; private static List<string> listing = new List<string>(); private void button1_Click(object sender, EventArgs e) { for (int i=1 ; i<5; i++) { name = i.ToString(); Work w = new Work(name); Thread t = new Thread(new ThreadStart(w.DoWork)); t.Start(); } } class Work { private string m_name; public Work(string name) { m_name = name; } public void DoWork() { for (int x = 0; x < 10; x++) { Form1.listing.Add(string.Format("Thread is working: {0} - Cycle: {1}", m_name, x)); // Form1.list1.Items.Add(string.Format("Thread is working: {0} - Cycle: {1}", m_name, x)); } } } private void button2_Click(object sender, EventArgs e) { list1.DataSource = listing; } }