Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
""Cross-thread operation not valid: Control 'listView1' accessed from a thread other than the thread it was created on.""
I found this problem. How can I solve it.
My code:


ListViewItem item1 = new ListViewItem(sKW,0);

item1.SubItems.Add(sPos);
item1.SubItems.Add(sDate);

listView1.Items.AddRange(new ListViewItem[]{item1});
}


for(int i = 0 ; i < listView1.Items.Count;i++)
{

string sKW = listView1.Items[i].SubItems[0].Text; // i got error here
SearchKWinGoogle(sKW,i);
progressBar1.Value = i+1;
Posted
Updated 25-Mar-13 22:03pm
v4

1 solution

Accessing UI element from different thread is not possible. Most possibly your code is running under different thread. If so then you can change your code and run it under main (ui) thread. If you need to access it from different thread then simply read the value as you normally do. Only to update the control, you need to switch to GUI thread.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900