以下是我的代码,原本是想用this.webb.ReadyState == WebBrowserReadyState.Complete来判断,加载完成,但实际运行时,怎么也无法判断!
        public SimulationClick()
        {
            InitializeComponent();
        }
        public string[] keywords = { "kw1", "kw2", "kw3", "kw4", "kw5", "kw6", "kw7" };
        public bool isLoading = true;
        WebBrowser webb = new WebBrowser();
        public string currentKeywords = string.Empty;
        private void btn_SimulationClick_Click(object sender, EventArgs e)
        {
            webb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(DocumentLoad());
            foreach (string str in keywords)
            {
                currentKeywords = str;
                isLoading = true;
                this.Invoke(new webbloading(loadingDoc));               
                while (isLoading)
                {                   
                    if (this.webb.ReadyState == WebBrowserReadyState.Complete)
                    {
                        this.ScreenStatus.Text += "关键词“" +str + "”请求完成!\r\n"; 
                        isLoading = false;
                        //do something
                    }
                }
            }        
        }      
        public delegate void webbloading();
        public void loadingDoc()
        {
            webb.Navigate("http://www.xxx.com/search.aspx?keywords=" + currentKeywords);
            this.ScreenStatus.Text += "关键词“" + currentKeywords + "”正在请求……\r\n";             
        }
我在网上也搜索一些案例,很多人都用Application.DoEvents()来等待本次加载完毕才执行下次循环,因为考虑到效率问题,所以决定不采用Application.DoEvents(),而用多线程来做!现在主要是不知道如何判断webbrowse加载完成。我也尝试过用,webb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(DocumentLoad());,在DocumentCompleted事件加委托方法来做,但最后也没有成功,因为总是加载最后一个关键词。对于此问题,在此请教各位有相关开发经验的大虾们……谢谢了!