JavascriptAsyncMethodHandler DelegateAwesomium.NET 1.7.6Awesomium.NET
Represents a method that will handle calls to one or more custom Javascript methods, asynchronously.

Namespace: Awesomium.Core
Assembly: Awesomium.Core (in Awesomium.Core.dll) Version:

public delegate void JavascriptAsyncMethodHandler(
	Object sender,
	JavascriptMethodEventArgs e


Type: SystemObject
The source of the event.
Type: Awesomium.CoreJavascriptMethodEventArgs
An JavascriptMethodEventArgs that contains the event data.

This delegate is used with BindAsync(JavascriptAsyncMethodHandler), BindAsync(String, JavascriptAsyncMethodHandler) and in DLR to tell the JSObject to create a custom method that does not return a value, therefore called asynchronously.

The benefits of an asynchronous handler are:

  • You can make synchronous invocations from inside an asynchronous handler.
  • You can pass JavaScript objects to an asynchronous handler.
For more details, read:
Note Note
A JavascriptAsyncMethodHandler method is always called in an asynchronous  Javascript Execution Context (JEC). Read this article for details about Javascript Execution Contexts.

private void OnDocumentReady( object sender, DocumentReadyEventArgs e )
    // Create a global object and assign it to a dynamic.
    dynamic myGlobalObject = (JSObject)webView.CreateGlobalJavascriptObject( "myGlobalObject" );

    // Make sure we have the object.
    if ( !myGlobalObject )

    // Create and bind a custom method dynamically. In a dynamic expression, use
    // a JavascriptAsyncMethodHandler delegate to create a JavaScript method
    // that does not return a value and is called asynchronously.
    myGlobalObject.myMethod = (JavascriptAsyncMethodHandler)OnCustomJavascriptMethod;

// Asynchronous JavaScript method handler.
private static void OnCustomJavascriptMethod( object sender, JavascriptMethodEventArgs e )
    IWebView webView = (IWebView)sender;

    if ( !webView.IsLive )

    // Access essential objects of the web-page's current JavaScript environment.
    var global = e.Environment;

    // We can have the same handler handling many remote methods.
    // Check here the method that is calling the handler.
    if ( e.MethodName == "myMethod" )
        // Make another synchronous call.
        var res = global.window.confirm( "Called from an asynchronous handler.\nDo you confirm?" );
See Also