Answer the question
In order to leave comments, you need to log in
Why is sometimes the text written 2 times, and not 1 time?
Such a joke. Sometimes it displays 2 texts at once, and not one.
I looked in the code through the debug, it seems it should not. What's the catch?
Website
string html = await browser.GetSourceAsync();
angle = parser.ParseDocument(html);
Plaintiffs.Text = string.Empty;
foreach (IElement element in GetElementsBySelector(PlaintiffsSelector))
{
Plaintiffs.Text += element.TextContent.Trim() + "\n\n";
}
private List<IElement> GetElementsBySelector(string Selector)
{
IElement element = angle.QuerySelector(Selector);
List<IElement> elements = new List<IElement>();
int i = 1;
while(element != null)
{
elements.Add(element);
i++;
Selector = Selector.Replace((i - 1).ToString(), i.ToString());
element = angle.QuerySelector(Selector);
}
return elements;
}
Answer the question
In order to leave comments, you need to log in
To solve your problem, you need to write your frame load event handler as shown below and remove the Invoke call from everywhere . Asynchronous methods return tasks for that, so that, among other things, you can work in the UI thread (write the main code) and it does not freeze.
If there are several frames on the page, then this handler will be called when each of them is loaded
private readonly string url = "https://kad.arbitr.ru/Card?number=";
private void OnWebBrowserFrameLoadEnded(object sender, FrameLoadEndEventArgs e)
{
Debug.WriteLine($"{nameof(OnWebBrowserFrameLoadEnded)}. " +
$"Frame.IsMain: {e.Frame.IsMain.ToString()}; e.Url: {e.Url};");
if (e.Frame.IsMain && e.Url.Contains(url))
{
Invoke((MethodInvoker)(async () =>
{
await UpdateData();
}));
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question