-
September 24th, 2011, 05:56 PM
#1
Cross-Thread Operation Not Valid
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)
-
September 25th, 2011, 03:21 PM
#2
Re: Cross-Thread Operation Not Valid
Originally Posted by kytro360
(I removed my postData and the site I am requesting too to protect my code form leechers)
Here's a head's up....
No one cares about code that can be found in any sample and that anyone can write.
If you don't want to post code, fine, but there isn't any need to comment about 'leechers'. It's insulting to folks on this site that are trying to help.
Now, to solve your problem, search bing or google for "Cross-thread operation not valid".
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|