1. 程式人生 > >WebBrowser載入完畢後再往下執行

WebBrowser載入完畢後再往下執行

System.Threading.AutoResetEvent obj = new System.Threading.AutoResetEvent(false);
     void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
   { 
      obj.Set();
   }
  
  private void button1_Click(object sender, EventArgs e)
   {
      this.webBrowser1.DocumentCompleted +=
                         new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);

      this.webBrowser1.Navigate("www.sina.com.cn");
      obj.Reset();
      while (obj.WaitOne(10, false) == false)
                    { Application.DoEvents(); }
      MessageBox.Show("");
    }