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()));
threads[p].Start();
}
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();
http.get(url);
MessageBox.Show(url);
listBox1.ClearSelected();
}
}