可能重复:
避免跨线程操作错误的最简洁和正确的方法?
运行我的程序时出现错误.... {“跨线程操作无效:控件 'listView1' 从创建它的线程以外的线程访问。”}
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?
我知道在一些教程中说使用调用?但我尝试了很多东西但仍然错误?
有手吗?