我有這樣的代碼,只需導航到一個網站web瀏覽器的執行流
class BrowsingUrl {
private System.Windows.Forms.WebBrowser nBrowser ;
private System.Windows.Forms.Form theFormLayout1;
public BrowsingUrl(System.Windows.Forms.Form theFormLayout) {
this.nBrowser = new System.Windows.Forms.WebBrowser();
this.nBrowser.Dock = System.Windows.Forms.DockStyle.Fill;
this.nBrowser.Location = new System.Drawing.Point(0, 0);
this.nBrowser.MinimumSize = new System.Drawing.Size(20, 20);
this.nBrowser.Name = "webBrowser1";
this.nBrowser.ScrollBarsEnabled = false;
this.nBrowser.Size = new System.Drawing.Size(1300, 700);
this.nBrowser.TabIndex = 0;
this.theFormLayout1 = theFormLayout;
this.theFormLayout1.Controls.Add(this.nBrowser);
this.nBrowser.Navigate("https://stackoverflow.com");
this.nBrowser.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.nBrowser_DocumentCompleted);
}
private void nBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
// do stuff
}
}
如果創建一個browsingurl反對一切工作正常,但如果創建了兩個對象,似乎是這兩個構造函數運行在同一時間我怎麼才能讓第二個對象等待,直到第一個終點執行
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void startbtn_Click(object sender, EventArgs e)
{
BrowsingUrl BrowsingUrl1 = new BrowsingUrl(this);
//wait till browsingUrl1 finish
BrowsingUrl BrowsingUrl2 = new BrowsingUrl(this);
}
}
可能重複http://stackoverflow.com/questions/583897/c-sharp-how-to-a-web-to-finish-loading-before-continued) – 2014-09-28 15:47:53
不幸的是不是同一個問題 – magicalll 2014-09-28 15:52:13
我想@magicalll想等待第一個'nBrowser_DocumentCompleted'在開始第二個構造函數之前完成。 – kennyzx 2014-09-28 15:53:16