我需要确保在使用javascript函数(AddToPage)将文本添加到webview后调用我的Play()函数。 await关键字是否确保javascript函数完全执行,或者它是否只等到调用完成后?
private async void AddChunk(ChunkEventArgs chunkargs)
{
Debug.WriteLine("AddChunk called: " + chunkargs.Text);
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,async () =>
{
if (!string.IsNullOrEmpty(chunkargs.Text))
{
string text = App.chunkparser.ParseChunk(chunkargs.Text);
Debug.WriteLine("calling addparsedchunk");
CurrentDocument.AddParsedChunk(App.chunkparser.ElementFromChunk);
await _webView.InvokeScriptAsync("AddToPage", new string[] { text });
if (App.settings.AutoPlay && !SpeechControl.IsSpeaking)
Play();
}
});
}
答案 0 :(得分:0)
InvokeScriptAsync
等待脚本结束。
Your app might appear unresponsive while scripts are running. Handle the LongRunningScriptDetected event to interrupt a long-running script.
,这清楚地表明该方法等待脚本完成