我构建了一个C#控制台应用程序,用于创建WebView
(Awesomium 1.7.4)并加载一些动态页面并截取屏幕截图。
一切都很好。
当我向ShowCreatedWebView
Event添加处理程序时,问题就开始了,这是在请求新视图时发生的。
在我的情况下,它是一个表单提交,它会加载文件下载页面。
添加处理程序后,我在等待第一个WebView
WebCore未初始化
我的代码中重要的部分:
处理程序:
...
WebCore.Download += onDownload;
webView.ShowCreatedWebView += onDownloadRequest;
webView.LoadingFrameComplete += (sender, e) =>
{
FrameHasError = false;
finishedLoading = true;
};
webView.LoadingFrame += (sender, e) =>
{
FrameHasError = false;
finishedLoading = false;
};
webView.LoadingFrameFailed += loadingFailed;
....
ShowCreatedWebView
处理程序:
private static void onDownloadRequest(object sender, ShowCreatedWebViewEventArgs e)
{
WebView webDownload = new WebView(e.NewViewInstance);
webDownload.Resize(1024, 768);
// Expecting a white picture but nothing is saved webDownload.Surface is null!?
surface = (BitmapSurface)webDownload.Surface;
surface.SaveToPNG(opt_target + "testNewView.png", true);
}
触发WebView
时的主ShowCreatedWebView
:
...
finishedLoading = false;
string jsActionDownloadFiles = HelperParser.jsLibActions("trigger-download-files");
//Triggers the form submit on the page:
webView.ExecuteJavascriptWithResult(jsActionDownloadFiles); //FIRES ShowCreatedWebView
while (!finishedLoading)
{
Thread.Sleep(Waits["web-loading"]);
WebCore.Update(); //ERROR OCCURS HERE AFTER THE ShowCreatedWebView FIRES
}
...
知道我错过了什么?