Contents - Index - Top


Asynchronous versus synchronous

 

A lot of the methods in WebView2 (the control from Microsoft that AntView provides access to) are asynchronous.

One reason for that is that interacting with servers on the web is asynchronous by nature.

You'll ask a server for something and it takes time to respond, or you ask the javascript engine to run something and it will return the results once done.

Another reason is that WebView2 itself is an out of process control and as such you are already communicating with the control in an asynchronous way.

 

That means that trying to approach problems in a synchronous way to an asynchronous interface tends to be problematic.

In fact Microsoft gets the question if they can provide a synchronous interface pretty regularly over at github.

 

See for example: https://github.com/MicrosoftEdge/WebView...issues/2117

 

and https://github.com/MicrosoftEdge/WebView...issues/1905

 

 

While the best and most flexible way to communicate with the WebView2 control is to use it asynchronously, not all development environments are well suited to develop in that way. Some cannot consume ActiveX events, others have trouble setting that up in a way that it works with the AntView control. 

As such as we have introduced synchronous wrappers for most methods in the AntViewDocument interface and we're gradually introducing more synchronous wrappers, also for the AntView control itself. 

 

One thing to remember is that you cannot start a synchronous method from within a WebView2 event. Doing so would block the event until it times out. As such we now detect that scenario and return the appropriate error ("trying to run from within WebView2 event").

 

If you need to use the asynchronous method from an event, then one way out is to start a timer and call the synchronous method from the timer event instead.

 

One last note: If your development environment does support asynchronous consumption of the API, then we strongly recommend to use that as it is the best supported interface closest to what Microsoft provides (and supports).

 


AntView - The MS Edge WebView2 ActiveX control Date last changed: 09/25/2024