private void btnScheduler_Click(object sender, EventArgs e) { TaskHelper.UITask.Run(() => { Log("开始"); LimitedTaskScheduler scheduler = new LimitedTaskScheduler(100); List <Task> taskList = new List <Task>(); for (int i = 0; i < 10; i++) { Task task = scheduler.Run(() => { //Thread.Sleep(100); this.TryBeginInvoke2(() => { Log("LimitedTaskScheduler测试"); }); }); taskList.Add(task); } Task.WaitAll(taskList.ToArray()); scheduler.Dispose(); }); }
public void Load(string url) { if (!string.IsNullOrWhiteSpace(url)) { loadingWait.Visibility = Visibility.Visible; Url = url; _scheduler.Run(() => { #region Wait WaitUtil.Wait(() => { if (this._browser == null) { return(false); } if (!this._browser.IsInitialized) { return(false); } if (!_isCefInited) { return(false); } bool isBrowserInitialized = false; this.Dispatcher.Invoke(() => { isBrowserInitialized = this._browser.IsBrowserInitialized; }); if (!isBrowserInitialized) { return(false); } return(true); }); #endregion _browser.Load(Url); }); } }
public bool OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser) { var chromiumWebBrowser = (ExtChromiumBrowser)browserControl; chromiumWebBrowser.Dispatcher.Invoke(new Action(() => { BrowserPopupWin win = new BrowserPopupWin(); win.ShowInTaskbar = false; win.Height = 0; win.Width = 0; win.Show(); IntPtr handle = new WindowInteropHelper(win).Handle; windowInfo.SetAsChild(handle); _scheduler.Run(() => { WaitUtil.Wait(() => chromiumWebBrowser.PostData); IRequest request = null; if (chromiumWebBrowser.PostData != null) { request = frame.CreateRequest(); request.Url = targetUrl; request.Method = "POST"; request.InitializePostData(); var element = request.PostData.CreatePostDataElement(); element.Bytes = chromiumWebBrowser.PostData; request.PostData.AddElement(element); chromiumWebBrowser.PostData = null; } chromiumWebBrowser.Dispatcher.Invoke(new Action(() => { NewWindowEventArgs e = new NewWindowEventArgs(targetUrl, request); chromiumWebBrowser.OnNewWindow(e); })); chromiumWebBrowser.Dispatcher.Invoke(new Action(() => { win.Close(); })); }); })); newBrowser = null; return(false); }