形成另一个线程。 错误:
仅分配,调用,增量,减量和新对象 表达式可以用作语句
有问题的一行:
string url = objectListView1.Invoke(new Action(() =>
objectListView1.SelectedItems[objectListView1.SelectedIndex].SubItems[7].Text));
C#代码:
void getThumbnail()
{
try
{
HtmlWeb web = new HtmlWeb();
string url = objectListView1.Invoke(new Action(() =>
objectListView1.SelectedItems[objectListView1.SelectedIndex].SubItems[7].Text));
HtmlAgilityPack.HtmlDocument htmldoc = web.Load(url);
htmldoc.OptionFixNestedTags = true;
var link = htmldoc.DocumentNode.SelectSingleNode("//link[@itemprop='thumbnailUrl']");
var href = link.Attributes["href"].Value;
pictureBox1.Invoke(new Action(() => pictureBox1.Load(href)));
}
catch (HtmlAgilityPack.HtmlWebException)
{
}
}
private void objectListView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
{
Thread thr = new Thread(() => getThumbnail());
thr.Start();
}
答案 0 :(得分:1)
string url = objectListView1.Invoke(new Action(() =>
objectListView1.
SelectedItems[objectListView1.SelectedIndex].
SubItems[7].Text));
Action
委托不会返回任何结果。如果您想返回string
,则需要使用Func<string>
:
string url = objectListView1.Invoke(new Func<string>(() =>
objectListView1.
SelectedItems[objectListView1.SelectedIndex].
SubItems[7].Text)) as string;