I'm working on an application and I want to create multiple threads, each thread must create a WebBrowser
, every WebBrowser
of these uses the method webBrowser_DocumentCompleted
.
How can each of the created WebBrowser
instances have it's own DocumentCompleted
handler instead of the same webBrowser_DocumentCompleted
method across all of them.
I explain :
in one case, an operation with a single web browser
int a = 0;
private void button1_Click(object sender, EventArgs e)
{
methode1();
}
private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (a == 1) methode2(wb);
if (a == 2) methode2(wb);
}
public void methode1()
{
webBrowser.Navigate("http://www.test.com");
a = 1;
}
public void methode2()
{
HtmlElement txt1 = webBrowser1.Document.GetElementById("tesxtbox1");
txt1.SetAttribute("value", "test");
webBrowser.Document.Forms[0].InvokeMember("submit");
a = 2;
}
public void methode3()
{
webBrowser.Navigate("http://www.test3.com");
}
but if I want to make multiple operation, ie in butoon1 I add :
private void button1_Click(object sender, EventArgs e)
{
for(int i=0; i<5 ;i++)
methode1();
}
then to do it, I think I must have several webbrowser, so the solution is to create a thread for each operation
private void button1_Click(object sender, EventArgs e)
{
for(int i=0; i<5 ;i++)
{
Thread thread = new Thread(new ThreadStart(method1));
thread.Start();
}
}
So each web browser created by a thread must have its own method webBrowser_DocumentCompleted
, to not be confused between the results of other web browser.
or, use the same method webBrowser_DocumentCompleted
for all created web browser, but the problem is how to specify which webbrowser, call the method webBrowser_DocumentCompleted.