无法转换lambda表达式&名字'_'在当前上下文中不存在
本文关键字:上下文 不存在 转换 表达式 名字 lambda | 更新日期: 2023-09-27 18:02:20
谁能帮我修理一下?我有两种类型的错误信息
-
名称'closure_'在当前上下文中不存在
-
无法将lambda表达式转换为'System '类型。委托",因为它不是委托类型
代码为
private void backgroundWorker3_DoWork(object sender, DoWorkEventArgs e)
{
HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument();
string text = this.textBox5.Text;
htmlDocument.LoadHtml(text);
HtmlNodeCollection htmlNodeCollection = htmlDocument.DocumentNode.SelectNodes("//img/@alt");
int num1 = 0;
int k = 0;
if (htmlNodeCollection == null || this.backgroundWorker3.CancellationPending)
return;
string links = "";
foreach (HtmlNode htmlNode in (IEnumerable<HtmlNode>) htmlNodeCollection)
{
HtmlNode aTag = htmlNode;
int num2 = int.Parse(this.textBox7.Text);
this._busy.WaitOne(-1);
if (!this.backgroundWorker3.CancellationPending)
{
++k;
this.Invoke((Delegate) (() => this.richTextBox4.AppendText(k.ToString() + "." + Environment.NewLine + aTag.InnerHtml + aTag.Attributes["alt"].Value + Environment.NewLine + Environment.NewLine)));
++num1;
}
this.Invoke((Delegate) (closure_0 ?? (closure_0 = (Action) (() => links = this.richTextBox4.Text + Environment.NewLine))));
System.IO.File.WriteAllText(this.textBox2.Text + "/Descriptions.txt", links);
if (num1 == num2)
{
this.backgroundWorker3.CancelAsync();
if (!this.backgroundWorker3.CancellationPending)
this._busy.Reset();
}
}
}
这是截图
谢谢
这一行是无用的代码:
this.Invoke((Delegate) (closure_0 ?? (closure_0 = (Action) (() => links = this.richTextBox4.Text + Environment.NewLine))));
您可以安全地将其替换为:
this.Invoke(new Action(() => { links = this.richTextBox4.Text + Environment.NewLine; }));
您的第一个问题是,在您所显示的代码中没有名为closure_0
的变量或类字段。
其次,您在UI上创建和调用操作的语法是复杂和错误的,请使用上述更简单的方法。