コード例 #1
0
        public Task RunScriptAsync(ScriptLambda script)
        {
            var    tcs     = new TaskCompletionSource <object> ();
            Action closure = () => {
                try {
                    script(GetGlobalObject());
                    tcs.TrySetResult(null);
                } catch (Exception e) {
                    tcs.TrySetException(e);
                }
            };

            // We must execute synchronously if already on the main thread,
            //  otherwise a Wait() on the returned task would deadlock trying to
            //  dispatch back to the main thread while it's blocking on the Wait().
            if (NSThread.IsMain)
            {
                closure();
            }
            else
            {
                webView.BeginInvokeOnMainThread(closure);
            }
            return(tcs.Task);
        }
コード例 #2
0
 /// <summary>
 /// Runs the specified script, possibly asynchronously.
 /// </summary>
 /// <remarks>
 /// This method may dispatch to a different thread to run the passed lambda.
 /// </remarks>
 /// <param name="script">A lambda that interacts with the passed JavaScript global object.</param>
 public Task RunScriptAsync(ScriptLambda script)
 {
     if (CanRunScriptOnMainThread)
     {
         script(GetGlobalObject());
         return(Task.FromResult <object> (null));
     }
     else
     {
         // This simply ensures we're not running on the UI thread..
         Action closure = () => script(GetGlobalObject());
         return(Task.Run(closure));
     }
 }
コード例 #3
0
 /// <summary>
 /// Runs the specified script, possibly asynchronously.
 /// </summary>
 /// <remarks>
 /// This method is a convenience for: <code>webView.AsHybridWebView ().RunScriptAsync (script)</code>
 /// This method may dispatch to a different thread to run the passed lambda.
 /// </remarks>
 /// <param name="webView">The Web View in which to run the script.</param>
 /// <param name="script">A lambda that interacts with the passed JavaScript global object.</param>
 public static Task RunScriptAsync(this UIWebView webView, ScriptLambda script)
 {
     return(webView.AsHybridWebView().RunScriptAsync(script));
 }
コード例 #4
0
 /// <summary>
 /// Runs the specified script, possibly asynchronously.
 /// </summary>
 /// <remarks>
 /// This method may dispatch to a different thread to run the passed lambda.
 /// </remarks>
 /// <param name="script">A lambda that interacts with the passed JavaScript global object.</param>
 public Task RunScriptAsync(ScriptLambda script)
 {
     return(Native.RunScriptAsync(script));
 }