Esempio n. 1
0
        private void CheckCompleted(object obj, EventArgs arg)
        {
            if (obj.GetType().Name == "RefreshThread")
            {
                RefreshThread thread = obj as RefreshThread;
                if (thread.Status == "Completed")
                {
                    this.CompletedCount++;
                }
            }

            if (obj.GetType().Name == "WbRefreshThread")
            {
                WbRefreshThread thread = obj as WbRefreshThread;
                if (thread.Status == "Completed")
                {
                    this.CompletedCount++;
                }
            }

            if (this.CompletedCount == this.threads.Count)
            {
                this.Completed(this.Completed, new EventArgs()); //发出警告
            }
        }
Esempio n. 2
0
        private static void Refresh(WbRefreshThread refresher, Proxy proxy)
        {
            WebBrowserEx wbWebBrowser = new WebBrowserEx();

            wbWebBrowser.ScriptErrorsSuppressed = true;

            if (refresher.useProxy)
            {
                wbWebBrowser.ProxyServer = proxy.IpAndPort;
            }
            else
            {
                wbWebBrowser.ProxyServer = "";
            }
            wbWebBrowser.Navigate(refresher.Url);

            Stopwatch sw = new Stopwatch();

            sw.Start();
            while (wbWebBrowser.ReadyState < WebBrowserReadyState.Complete)
            {
                Application.DoEvents();
                if (sw.ElapsedMilliseconds > refresher.timeOut * 1000)
                {
                    throw new WebException(WebExceptionStatus.Timeout.ToString());
                }
            }
            sw.Stop();
            refresher.SuccessCount++;
            refresher.Description = wbWebBrowser.ProxyServer + "刷新成功!";
        }
Esempio n. 3
0
        private static void DoWork(object data)
        {
            WbRefreshThread refresher = (WbRefreshThread)data;

            try
            {
                List <Proxy> pList = refresher.proxyList;

                foreach (Proxy proxy in pList)
                {
                    refresher.Description = proxy.IpAndPort + "开始刷新...";
                    try
                    {
                        Refresh(refresher, proxy);
                        RefreshForm fm = (RefreshForm)Application.OpenForms["RefreshForm"];
                        if (null != fm)
                        {
                            fm.UpdateDataGrid();
                        }
                    }
                    catch (Exception exx)
                    {
                        refresher.Description = "出错啦:" + exx.Message;
                        refresher.FailedCount++;
                    }
                    refresher.Status = refresher.thread.ThreadState.ToString();
                }

                refresher.Status = "Completed";
            }
            catch (Exception ex)
            {
                // 线程被放弃
                refresher.Description = "出错啦:" + ex.Message;
                refresher.FailedCount++;
                refresher.Status = "Completed";
                Console.WriteLine(ex.Message);
                //WriteException(ex);
            }
            finally
            {
                refresher.TotalCount++;
                refresher.OnCompleted();
            }
        }
Esempio n. 4
0
        public void Stop()
        {
            foreach (object thread in this.Threads)
            {
                if (thread.GetType().Name == "RefreshThread")
                {
                    RefreshThread t = (RefreshThread)thread;
                    t.Abort();
                }

                if (thread.GetType().Name == "WbRefreshThread")
                {
                    WbRefreshThread t = (WbRefreshThread)thread;
                    t.Abort();
                }
            }
            this.Completed(this.Completed, new EventArgs()); //发出警告
        }
Esempio n. 5
0
 public void Start()
 {
     foreach (string url in urlList)
     {
         if (this.refreshType == "Quickly")
         {
             RefreshThread thread = new RefreshThread(proxyList, url, this.SleepTime, this.TimeOut);
             thread.Completed += new RefreshThread.CompletedEventHandler(this.CheckCompleted);
             thread.Start();
             threads.Add(thread);
         }
         else
         {
             WbRefreshThread thread = new WbRefreshThread(proxyList, url, useProxy, this.TimeOut);
             thread.Completed += new WbRefreshThread.CompletedEventHandler(this.CheckCompleted);
             thread.Start();
             threads.Add(thread);
         }
     }
 }