2016-08-13 57 views
0

任何人都可以幫我解決它嗎? 我有2類型的錯誤消息無法轉換lambda表達式&名稱'_'在當前上下文中不存在

  1. 「closure_」沒有在當前的背景下存在的名稱

  2. 無法轉換lambda表達式鍵入「System.Delegate」,因爲 它是不是委託型

的代碼是:

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(); 
    } 
    } 
} 

Here is screenshoot

三江源

回答

0

此行是無用代碼:

this.Invoke(new Action(() => { links = this.richTextBox4.Text + Environment.NewLine; })); 

你的第一個問題是,有:

this.Invoke((Delegate) (closure_0 ?? (closure_0 = (Action) (() => links = this.richTextBox4.Text + Environment.NewLine)))); 

您可以放心地將其替換爲沒有名爲01的變量或類字段只要您顯示的代碼爲。其次,在UI上創建調用動作的語法很複雜且錯誤,請使用上述簡單方法。

+0

謝謝你這麼多,我是c#中的新手,我丟失了我非常老的源代碼,所以我用jetbrain dotpeek反編譯我的程序。我真的不明白一些缺少的代碼。現在你解決了我的問題,再一次,謝謝你, – userrrrrrr

相關問題