I am trying to run the following code in a thread but I keep getting this error for both listboxes:


Cross-thread operation not valid


Heres the code I am using:

Code:
     
    try
    {
     
    for (int i = 0; i < listBox4.Items.Count; i++)
    {
    listBox4.SetSelected(i, true);
    listBox5.SetSelected(i, true);
    listBox4.SelectedItem.ToString();
     
    string[] details = { listBox4.SelectedItem.ToString(), listBox5.SelectedItem.ToString() };
     
    foreach (string element in details)
    {
     
     
    string postData = "";
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("");
    request.ContentType = "application/x-www-form-urlencoded";
    request.ContentLength = postData.Length;
    request.Method = "POST";
    request.KeepAlive = true;
     
     
    Stream response = request.GetRequestStream();
    byte[] postBytes = Encoding.ASCII.GetBytes(postData);
    response.Write(postBytes, 0, postBytes.Length);
     
     
     
     
    response.Close();
    response.Dispose();
     
    }
     
     
     
     
     
     
    }
     
     
    }
     
     
     
     
    catch (Exception ex)
    {
     
    MessageBox.Show(ex.Message);
     
    }
    }

(I removed my postData and the site I am requesting too to protect my code form leechers)