我想在 CEF3/Xilium CefGlue rom 非 UI 线程(屏幕外浏览器)中获取网页源
我这样做
internal class TestCefLoadHandler : CefLoadHandler
{
protected override void OnLoadStart(CefBrowser browser, CefFrame frame)
{
// A single CefBrowser instance can handle multiple requests for a single URL if there are frames (i.e. <FRAME>, <IFRAME>).
if (frame.IsMain)
{
Console.WriteLine("START: {0}", browser.GetMainFrame().Url);
}
}
protected override void OnLoadEnd(CefBrowser browser, CefFrame frame, int httpStatusCode)
{
if (frame.IsMain)
{
MyCefStringVisitor mcsv = new MyCefStringVisitor();
frame.GetSource(mcsv);
Console.WriteLine("END: {0}, {1}", browser.GetMainFrame().Url, httpStatusCode);
}
}
}
class MyCefStringVisitor : CefStringVisitor
{
private string html;
protected override void Visit(string value)
{
html = value;
}
public string Html
{
get { return html; }
set { html = value; }
}
}
但是调用
获取源(...)是异步的,所以我需要等待调用发生,然后再尝试对结果做任何事情。
我怎样才能等待呼叫发生?