U
U
Uncle Bogdan2021-06-03 17:04:01
C++ / C#
Uncle Bogdan, 2021-06-03 17:04:01

Why does a deadlock or something like that happen?

private string GetHTMLFromWebBrowser()
        {

            // Get the html source code from the main Frame.
            // This is displaying only code in the main frame and not any child frames of it.
            Task<String> taskHtml = browser.GetBrowser().MainFrame.GetSourceAsync();

            string response = taskHtml.Result;
            return response;
        }

        private void WebBrowserFrameLoadEnded(object sender, FrameLoadEndEventArgs e)
        {
            html = GetHTMLFromWebBrowser();


Tipo further html = nothing is executed.
Through debigger I looked, it stops at string response = taskHtml.Result;

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Voland69, 2021-06-03
@motkot

Result of Task is a blocking operation. Here is more about deadlock
. I would do this - waiting for the completion of an async operation in a separate thread - upon completion of waiting for the event, the subscriber of which will update the data on the form.

V
Vasily Bannikov, 2021-06-03
@vabka

Task<String> taskHtml = browser.GetBrowser().MainFrame.GetSourceAsync();

            string response = taskHtml.Result;

Yes, deadlock. It is impossible to call .Result in winforms.
Use async-await and ConfigureAwait(false) where possible.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question