2024-12-05, 11:07:06
Hi,
WebView2 has an asynchronous interface and as such having a loop and waiting for an event to be raised... doesn't work, as the windows messages never end up getting processed in your tight loop.
See also: No UI threads in an event and in particular the link in there that goes to Microsoft's explaining about the threading model the control uses.
Also see: Asynchronous versus Synchronous
As a result I tend to use timers to work around the inability of a programming language to deal with asynchronous interfaces.
An example is here: VB6 - Exchange Rates example
However.. that's a real pain to program and makes code somewhat difficult to follow.
So... that's why AntView has a lot of synchronous versions of the original asynchronous API methods.
In your case, instead of using the navigate method, I suggest to use navigateSync instead, as then you can drop all the loops where you are waiting for the navigation to complete.
Hope this helps,
--
Wil
WebView2 has an asynchronous interface and as such having a loop and waiting for an event to be raised... doesn't work, as the windows messages never end up getting processed in your tight loop.
See also: No UI threads in an event and in particular the link in there that goes to Microsoft's explaining about the threading model the control uses.
Also see: Asynchronous versus Synchronous
As a result I tend to use timers to work around the inability of a programming language to deal with asynchronous interfaces.
An example is here: VB6 - Exchange Rates example
However.. that's a real pain to program and makes code somewhat difficult to follow.
So... that's why AntView has a lot of synchronous versions of the original asynchronous API methods.
In your case, instead of using the navigate method, I suggest to use navigateSync instead, as then you can drop all the loops where you are waiting for the navigation to complete.
Hope this helps,
--
Wil