Hello, I am trying to multithread a listBox which has URL's in it.

Basically what I am trying to do is to make it so each thread I make, will visit one of the URL's in the listBox and do a GET request.

I was wondering how do I make it so each thread I make, visit a different site in the list, not the same site?

For example, what happens now is, if I pick 3 threads, those 3 threads will visit the same sites 3 times.

How can I do it so if my listBox has 3 sites in the list, those 3 threads will visit a different site in the listBox so it'll finish faster, and not the same sites?

Heres the code I am working with right now. Help is appreciated:

This is the multithreading code (the code that creates the threads):

            CheckForIllegalCrossThreadCalls = false;
            var threads = new Thread[(int)numericUpDown1.Value]; 
            for (int p = 0; p < (int)numericUpDown1.Value; p++)
                threads[p] = (new Thread(() => selectall()));

And here is the method I make each thread go to:

public void selectall()
            for (int i = 0; i< listBox1.Items.Count;i++)
                listBox1.SetSelected(i, true);
                CheckForIllegalCrossThreadCalls = false;
                string url = listBox1.SelectedItem.ToString();
                HttpInterface http = new HttpInterface();

4 Years
Discussion Span
Last Post by kytro360

Will that solve the issue?

I am aware Im not invoking but I can worry about that later.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.