views:

262

answers:

2

I am using the WebBrowser control in a windows form C# project and wanted to know if there are any limitations of how many instances of such application you can have running at the same time. (in other words does MSFT enforce any limitations other than physical machine limits - CPU/memory etc)

A: 

Try out this code and see what happens:

int count = 0;
List<Form> forms = new List<Form>();
try
{
    while (true)
    {
        Form f = new Form();
        WebBrowser wb = new WebBrowser();
        f.Controls.Add(wb);
        f.Show();
        wb.Url = new Uri(@"http://www.stackoverflow.com");
        forms.Add(f);
        count++;
    }
}
catch
{
    MessageBox.Show(count.ToString());
}

I'm going to guess it's hundreds, but I dunno.

MusiGenesis
Move the try/catch outside the `while` loop, or you'll never stop looping.
SLaks
@SLaks: done. You have shamed me. :) I was actually figuring I would just hit the `stop` button in Visual Studio once the MessageBox popped up.
MusiGenesis
+1  A: 

There are no artificial limitations on the WebBrowser control.

However, it uses IE's rendering engine (whatever version is installed on the end-user's computer), so it uses a fair bit of memory.

What are you trying to do?

If you're trying to write a web browser, I recommend that you use a better rendering engine, such as WebKit or Gecko.

SLaks
Such a choice involves a set of tradeoffs. If you ship WebKit or Gecko, the install will be larger, and you have to issue patches everytime a security bug is found with those components. On the other hand, the IE components will be updated when IE updates are installed.
EricLaw -MSFT-
True. However, using the IE engine means that he'll be increasing the IE6 userbase. http://mashable.com/2009/07/16/ie6-must-die/
SLaks
i am well aware of the other rendering engines, and pros cons -however i need to use IE.The question remains what are the limitations? I also expected a memory utilization issue, but when i did some test above 10 instances i hit some sort of wall...and it was not memory, it did seem CPU related, but that did not make sense considering the machine had 8 cores.
webly
I don't know why that might happen.
SLaks