Exemple #1
0
        //Task分配循环
        private void BK_DoWork(object sender, DoWorkEventArgs e)
        {
            while (TaskHelper.HasTask())
            {
                CustomChrominWebBrowser browser = null;     //尝试从对象池中获取一个可用对象

                while (browser == null)
                {
                    //任务队列还有任务
                    browser = BH.Get();
                    Thread.Sleep(2000);
                    //LogHelper.Debug("继续 等待可用对象");
                }
                {
                    var _MainTask = TaskHelper.PopTask();
                    if (_MainTask == null)
                    {
                        return;
                    }
                    //LogHelper.Debug(string.Format("取得任务[{0}],及可用对象", _MainTask.Action));

                    //LogHelper.Debug(string.Format("池=>{1}/{0} ", BH.GetPoolSize(), BH.GetObjectSize()));
                    browser.Info = _MainTask;
                    //获取到可用对象则进行解析任务

                    browser.RequestHandler = new CustomRequestHandler();
                    if (browser.LifeSpanHandler == null)
                    {
                        browser.LifeSpanHandler = LifeSpanHandler;
                    }
                    browser.LoadHandler = new CustomLoadHandler();
                    ((CustomLoadHandler)browser.LoadHandler).OnStateChange += Browser_StateChanged;

                    browser.FrameLoadStart -= Browser_FrameLoadStart;
                    browser.FrameLoadStart += Browser_FrameLoadStart;

                    var page = new ChrominViewModel(browser);
                    //PreLoad = page;
                    App.Current.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        browser.Address = browser.Info.Action;
                        TaskList.Add(page);
                    }));
                }
            }
        }