I have created an application which creates multiple webbrowser controls at runtime...now i want to clean up memory when these webrowsers are deleted see the code below please let me know how can i do it(i have tried dispose method but no luck)
Creation on dynamic web browsers on button click
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i = 0
Dim y = 0
For i = 0 To (ListBox1.SelectedIndices.Count - 1)
Dim t As System.Windows.Forms.AnchorStyles = AnchorStyles.Top
Dim b As System.Windows.Forms.AnchorStyles = AnchorStyles.Bottom
Dim r As System.Windows.Forms.AnchorStyles = AnchorStyles.Right
Dim s = ListBox1.Items(ListBox1.SelectedIndices.Item(i)).ToString()
Dim TT As New TEST_TABS
TT.wb = New WebBrowser
TT.wb.AllowNavigation = True
TT.wb.Navigate(s)
TT.wb.Location = New Point(0, 0)
TT.wb.Size = TabControl1.Size
TT.wb.Name = s+"e"
TT.wb.ScriptErrorsSuppressed = True
'//////////////////////////////////////////////////////////////////////////'
' TT.wb.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
' Or System.Windows.Forms.AnchorStyles.Left) _
' Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
'///////////////////////////////////////////////////////////////////////////'
TT.pb = New ProgressBar
TT.pb.Name = s + "p"
TT.pb.Location = New Point(y, 0)
TT.pb.Size = New Size(125, 24)
'TT.pb.Size = TabControl1.Size
TT.pb.Visible = True
Me.SplitContainer1.Panel2.Controls.Add(TT.pb)
y += 126
Dim tab_page As New TabPage
tab_page.Name = s
tab_page.Text = s
tab_page.Font = New System.Drawing.Font("Calibri", 22)
tab_page.Controls.Add(TT.wb)
TabControl1.Controls.Add(tab_page)
TabControl1.SelectedIndex = i
Next i
i = 0
For Each tp As TabPage In TabControl1.TabPages
ListBox1.Items.Remove(tp.Name)
Next
Button1.Enabled = False
Button2.Enabled = True
Panel1.Hide()
End Sub
I want to remove memory used by these dynamic webbrowsers on below click
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
For Each tp As TabPage In TabControl1.TabPages
tp.Controls.Item(0).Dispose()
Me.SplitContainer1.Panel2.Controls.Item(tp.Name.ToString + "p").Dispose()
Next
'TabControl1.TabPages.Clear()
Button1.Enabled = True
Panel1.Show()
End Sub
Below is the TEST_TABS class
Public Class TEST_TABS
Public WithEvents wb As New WebBrowser
Public WithEvents pb As New ProgressBar
Dim page_counter As Integer = 0
Private Sub wb_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles wb.DocumentCompleted
' MsgBox(page_counter)
page_counter += 1
If wb.DocumentText.Contains(WindowsApplication1.My.Resources.Resource1.loginpage) Then
wb.Document.GetElementById("username-id").SetAttribute("value", Form1.ComboBox1.SelectedItem.ToString)
wb.Document.GetElementById("pwd-id").SetAttribute("value", Form1.ComboBox1.SelectedItem.ToString)
wb.Document.GetElementById("login").InvokeMember("click")
End If
If page_counter = 1 Then
End If
End Sub
Private Sub wb_ProgressChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles wb.ProgressChanged
wb.Size = Form1.TabControl1.Size
If (e.CurrentProgress >= 0 And e.CurrentProgress < 100) Then
pb.Maximum = 100
pb.Value = Convert.ToInt32(e.CurrentProgress)
End If
End Sub
End Class