日期:2014-05-18 浏览次数:20923 次
WebBrowser[] web1=new WebBrowser[99]; bool[] m_boolWeb = new bool[99]; string[] html = new string[99]; private void Form1_Load(object sender, EventArgs e) { Thread oThread = new Thread(new ParameterizedThreadStart(StartAspxTaskSearch)); oThread.IsBackground = true; oThread.Priority = ThreadPriority.Lowest; oThread.ApartmentState = ApartmentState.STA; oThread.Start(1); } private void StartAspxTaskSearch(object str) { try { html[1] = ""; this.Invoke(new EventHandler(this.invokeTest)); web1[1].DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(web1_DocumentCompleted); web1[1].Name = "1"; web1[1].Navigate("http://xxxx.com/InfoList.aspx?type=es"); while (!M_boolWeb[1]) { //在这里没有办法读取web1[intThreadBH].Document.Body.InnerHtml,i不然可以用HTML里面的判断是否翻页了 Thread.Sleep(800); } MessageBox.Show(html[1]); } catch(Exception ex) { } } private void web1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { int intThreadBH = Convert.ToInt32(((WebBrowser)sender).Name); web1[intThreadBH].Document.All["ctl00$ContentPlaceHolder1$GridView1$ctl38$txtPage"].SetAttribute("value", "8");//8是变量 web1[intThreadBH].Document.InvokeScript("__doPostBack", new object[] { "ctl00$ContentPlaceHolder1$GridView1$ctl38$linkGo", "" }); while (web1[intThreadBH].StatusText != "完成") { // timer1.Enabled = false; } html[intThreadBH] = web1[intThreadBH].Document.Body.InnerHtml; m_boolWeb[intThreadBH] = true; } public void invokeTest(object sender, EventArgs e) { web1[1] = new WebBrowser(); this.Controls.Add(web1[1]); }