Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

start a new instance of webbrowser control in vb.net

Posted on 2009-05-07
11
Medium Priority
?
886 Views
Last Modified: 2013-12-20
Hi,
   I'm using vb.net (visual studio 2008). I am finding that the webbrowser control is leaking memory (as I have verified in many other psots on the internet). This happens when it stays maximized but is cleared when minimized. what is an easy way to load the webbrowser again after using the dispose method? The browser is automated and runs in a loop and I need it to reload in the loop after the webbrowser.dispose call.

Any help is appreciated.
webbrowser.dispose

Open in new window

0
Comment
Question by:tommycod
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24328063
Can't you just do a webbrowser = new WebBrowser() inside your loop?
0
 

Author Comment

by:tommycod
ID: 24328157
Hi,
  tried that, but once webbrowser.dispose  is called I can no longer see the webbrowser on the form.. tried using the .show method as well... no luck.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24330352
You need to add it back to the Controls collection of the form (or container). You may want to copy the initialization code from the Designer file in order to have the browser appear as it did before the dispose.
private void Form1_MouseDoubleClick(object sender, MouseEventArgs e)
{
    this.webBrowser1.Dispose();
    this.webBrowser1 = new WebBrowser();
    // 
    // From Designer.cs
    //             
    this.webBrowser1.Dock = System.Windows.Forms.DockStyle.Bottom;
    this.webBrowser1.Location = new System.Drawing.Point(0, 96);
    this.webBrowser1.MinimumSize = new System.Drawing.Size(20, 20);
    this.webBrowser1.Name = "webBrowser1";
    this.webBrowser1.Size = new System.Drawing.Size(292, 177);
    this.webBrowser1.TabIndex = 0;
    this.Controls.Add(this.webBrowser1);
}

Open in new window

0
A new era in Cloud training has arrived.

A day that will go down in Cloud history.. But are you ready for it? Will you accept this Cloud challenge?

 

Author Comment

by:tommycod
ID: 24330517
 Where exactly should I put this code? Can it be in my loop?
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24331145
It can go in your loop.

You are aware that calling Dispose() has a performance cost, aren't you? I'm not trying to discourage you from using it, but I just want you to be aware (since you mention putting it in the loop) that your app *could* get sluggish depending on how often you will be calling Dispose().
0
 

Author Comment

by:tommycod
ID: 24331746
kaufmed,
   Wasnt aware of that... do you have any other suggestions to get back the memory leak that happens when using the webbrowser control in vb.net? It has been said by minimizing the app you can see the memory increase and slightly restore.. but would have to have it 'auto minimize' within a timer just to correct this problem... seems rather half @ssed to have to cod eit this way.... thanks.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24332263
I may have misspoke. I was thinking of calling GC.Collect() which does put a hit on the system. You should be able to call Dispose() without incident.
0
 

Author Comment

by:tommycod
ID: 24335843
kaufmed,
   I need a version of the code for vb.net(2008) I believe your code is for C?
Thanks.
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 24336049
Sorry... sometimes it's hard being bilingual ;)
Private Sub Form1_MouseDoubleClick(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Form1.MouseDoubleClick
{
    Me.webBrowser1.Dispose();
    Me.webBrowser1 = new WebBrowser();
    // 
    // From Designer.cs
    //             
    Me.webBrowser1.Dock = System.Windows.Forms.DockStyle.Bottom;
    Me.webBrowser1.Location = new System.Drawing.Point(0, 96);
    Me.webBrowser1.MinimumSize = new System.Drawing.Size(20, 20);
    Me.webBrowser1.Name = "webBrowser1";
    Me.webBrowser1.Size = new System.Drawing.Size(292, 177);
    Me.webBrowser1.TabIndex = 0;
    Me.Controls.Add(Me.webBrowser1);
}

Open in new window

0
 

Author Comment

by:tommycod
ID: 24380505
Kaufmed,
   Almost got it.. problem I'm having is trying to get it back to being resizable with the SplitContainer control.. i tried reseting the ancor and fill but this now only pertains to the main form (as it ancors there and fills the full form).  Any help is appreciated. Thanks!
0
 

Author Comment

by:tommycod
ID: 24380614
i think I found the answer.. I copied the code from the designer.vb
thanks for all your help. points to Kaufmed
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

664 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question