I wrote a extension for cross thread update a RichTextBox with a HTML text (parsed with HtmlAgilityPack). Now I need plain text too, stripped from HTML tags and this is exact innerText return.
But how to return from delegate too?
public static string AppendHTMLText(this RichTextBoxEx box, string html)
{
// cross thread allowed
if (box.InvokeRequired)
{
box.Invoke((MethodInvoker)delegate()
{
return AppendHTMLText(box, html); // ???
});
}
else
{
HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
//document.OptionFixNestedTags = false;
//document.OptionCheckSyntax = false;
//document.OptionWriteEmptyNodes = true;
document.LoadHtml(html);
HtmlAgilityPack.HtmlNode doc = document.DocumentNode.SelectSingleNode("/");
HtmlAgilityPack.HtmlNodeCollection nodes = doc.ChildNodes;
parseHTML(doc.ChildNodes, box);
return doc.InnerText;
}
}
}
Thank you!