These calls are naturally synchronous, but often it makes sense to process them asynchronously, to avoid otherwise possible reentrancy into JavaScript code. You could use SynchronizationContext.Post for that.
E.g. you call window.external.TestMethod()
from JavaScript. On the .NET side it may look like this:
this.webBrowser.ObjectForScripting = new ObjectForScripting(this.webBrowser);
// ...
[ComVisible(true), ClassInterface(ClassInterfaceType.None)]
public class ObjectForScripting
{
WebBrowser _browser;
SynchronizationContext _context = SynchronizationContext.Current;
public ObjectForScripting(WebBrowser browser)
{
_browser = browser;
}
public void TestMethod()
{
_context.Post(_ =>
{
_browser.Document.InvokeScript("alert", new object[] {
"Process a call from JavaScript asynchronosuly." });
}, null);
}
}