Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C ASP.NET
""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 25-Mar-13 21:54pm
Edited 25-Mar-13 22:03pm
v4

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 6,649
1 Sergey Alexandrovich Kryukov 6,270
2 CPallini 5,190
3 George Jonsson 3,574
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 26 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100