Answer the question
In order to leave comments, you need to log in
Weird errors when running the HtmlAgilityPack.HtmlDocument.LoadHtml method. What to do?
Some terrible errors when running the HtmlAgilityPack.HtmlDocument.LoadHtml function.
Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.
Or
Unexpected error.
public partial class Form1 : Form
{
private ChromiumWebBrowser browser;
private string html;
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
HtmlNodeCollection node;
public Form1()
{
InitializeComponent();
InitializeChromium();
browser.FrameLoadEnd += WebBrowserFrameLoadEnded;
}
private async Task<string> GetHTMLFromWebBrowser()
{
string TaskHtml = await browser.GetBrowser().MainFrame.GetSourceAsync().ConfigureAwait(false); // cefsharp браузер дает html, не важно.
return TaskHtml;
}
private async void WebBrowserFrameLoadEnded(object sender, FrameLoadEndEventArgs e)
{
html = await GetHTMLFromWebBrowser();
if(html != null)
{
doc.LoadHtml(html);
// дальше доходит редко, В 1 из 5 почему-то срабатывает.
}
}
}
Answer the question
In order to leave comments, you need to log in
You cannot access it from two threads at the same time.
Wrap in a lock
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question