Click here to Skip to main content
11,638,173 members (72,154 online)
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 jyo.net 322
1 Sergey Alexandrovich Kryukov 314
2 stibee 303
3 Mika Wendelius 185
4 Richard Deeming 180
0 OriginalGriff 9,051
1 Sergey Alexandrovich Kryukov 8,773
2 Mika Wendelius 7,034
3 Suvendu Shekhar Giri 2,425
4 F-ES Sitecore 2,408


Advertise | Privacy | Mobile
Web01 | 2.8.150728.1 | Last Updated 26 Mar 2013
Copyright © CodeProject, 1999-2015
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