Tom
Tom

Reputation: 3627

WebView2 ExecuteScript not returning

I have encountered a very rare case where it seems ExecuteScript does not return?

FWebBrowser.ExecuteScript('document.documentElement.outerHTML',
        procedure (const AStrResult: string)
        begin
          // never returns here
          TmpGetDocumentAsStr := AStrResult;
          TmpCS.Acquire;
          TmpExecuted := True;
          TmpCS.Release;
        end
      );

So my code underneath waiting for TmpExecuted to be true (loop with checking value and sleeping) just continues forever.

Now, I can of course exit myself efter 100000 miliseconds or whatever. But I would prefer if ExecuteScript would return itself after x amount of time.

Am I missing something?

Upvotes: 1

Views: 492

Answers (1)

David Risney
David Risney

Reputation: 4377

If you call a WebView2 async method, then block that same UI thread with a loop that sleeps or otherwise isn't processing window messages then the WebView2 async method will never complete. You'll need to return back to the message loop for the WebView2 to receive the message that the async method has completed. This is described more in the WebView2 Threading Model document.

Upvotes: 0

Related Questions