Possible Duplicate:
Most concise and proper way of avoiding cross thread operation error?
I got error when running my programs….
{“Cross-thread operation not valid: Control ‘listView1’ accessed from a thread other than the thread it was created on.”}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) {
TestObject argumentTest = e.Argument as TestObject;
string[] lines = argumentTest.ThreeValue.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
foreach (string vr in lines)
{
string country = argumentTest.OneValue.Trim();
string url = vr + country + '/code/' + argumentTest.TwoValue.Trim();
string sourceCode = WorkerClass.getSourceCode(url);
document.LoadHtml(sourceCode);
var title = document.DocumentNode.SelectSingleNode("//title");
var desc = document.DocumentNode.SelectSingleNode("//div[@class='productDescription']");
//-- eksekusi title
string isititle = title.InnerText;
string isititle2 = isititle.Replace("droidflashgame: ", "");
string isititle3 = Regex.Replace(isititle2, "[^A-Za-z0-9 ]+", "");
string isititle4 = isititle3.Substring(0, Math.Min(isititle3.Length, 120));
//-- Adding to list view for next step...
ListViewItem abg = new ListViewItem(isititle3);
abg.SubItems.Add(isititle4);
listView1.Items.Add(abg); // ERROR in Here?
I knew in some tutorial said using invoke? but I tried many thing but still error?
Any hand?
Try this .This works fine for me