foreach (var url in urls) { var loaded = false; Action<object, FrameLoadEndEventArgs> frameLoadEndProc = (s, args) => { if (args.Frame.IsMain && args.Frame.Url == url.Value) { loaded = true; } }; var frameLoadEndEventHandler = new EventHandler<FrameLoadEndEventArgs>(frameLoadEndProc); // 订阅事件处理程序 browser.FrameLoadEnd += frameLoadEndEventHandler; //加载url并等待完成 browser.Load(url); var start = DateTime.Now; while (!loaded) { //最多加载10s if (DateTime.Now <= start + TimeSpan.FromSeconds(10)) { Application.DoEvents(); continue; } break; } //your code here // 取消订阅事件处理程序 browser.FrameLoadEnd -= frameLoadEndEventHandler; }
标签:cefsharp,提取,url,args,DateTime,var,loaded,页面 From: https://www.cnblogs.com/nanfei/p/17762947.html