Reputation: 3627
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
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