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); }
public static void FireEvent(this UIWebView source, string EventName, Object Data) { // call javascript event hanlder code string json = SimpleJson.SerializeObject(Data); source.BeginInvokeOnMainThread(delegate { source.EvaluateJavascript(string.Format("Mt.App._dispatchEvent('{0}', {1});", EventName, json)); }); }