Create various instances of WebBrowser and store in a WebBrowser array, using VS.NET 2005

Z

zorhel

Greetings,
I need to create a lot of instances of WebBrowsers (let's try 100) and store
that in a WebBrowser[] array according my following code, using Visual
Studio 2005 Beta.

private class Test
{
private WebBrowser[] _browser;

private void OpenBrowser()
{
for(int i=1; i<=100; i++)
{
_browser = new WebBrowser();
_browser.Navigate(http://localhost/Tests/WebEvents/main.aspx);
}
}
}

The problem is, when I see how many sessionId was create, I see just 2!
What is the problem of this code?
Please, how can I fix this problem?

Thanks in advance.

zorhel
 
S

Sijin Joseph

I think that since the client info's are the same for all the
webbrowsers, it is considering your browsers as coming from the same
machine and hence is not creating seperate sessions for them. You have
to realize that even the cookies are shared by the different instances
of the webbrowser control. You may have to tweak the individual
user-agent strings if possible to get different sessions.

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
 
K

Kevin Yu [MSFT]

Hi zorhel,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that when you're creating an array of
WebBrowser, the session count only grows by 2. If there is any
misunderstanding, please feel free to let me know.

Based on my research, there are some mistakes in the code you have provided.

1. A class cannot be declared as private explicitly. Because it is private
by default.
2. The WebBrowser array hasn't been initialized. So if you run the code, a
NullReferenceException will be thrown.
3. The index of an array in C# is zero-based. So the index of the array is
0 to 99.

Here I have made some changes to the code

class Test
{
private WebBrowser[] _browser;

private void OpenBrowser()
{
this._browser = new WebBrowswer[100];
for(int i=0; i<100; i++)
{
_browser = new WebBrowser();
_browser.Navigate(http://localhost/Tests/WebEvents/main.aspx);
}
}
}

With this code, we can see session count grows by 10 to 20 on the
performance monitor. This is because IE does cache on the client side, so
not each request is send to the IIS server.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top