I have this code which simply navigates to a website
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
}
}
If a create one browsingurl object everything works fine but if create two objects it seems to be that the two constructors runs at the same time how can I let the second object wait until the first one end execution
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);
}
}