【发布时间】:2014-09-28 15:04:16
【问题描述】:
我有这段代码,它只是导航到一个网站
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
}
}
如果创建一个浏览 URL 对象一切正常,但如果创建两个对象似乎是两个构造函数同时运行,我怎样才能让第二个对象等到第一个对象结束执行
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);
}
}
【问题讨论】:
-
很遗憾不是同一个问题
-
我认为@magicalll 想等待第一个
nBrowser_DocumentCompleted完成后再开始第二个构造函数。 -
是的@kennyzx 这正是我要找的
标签: c#