code
Sure,
This is what I do during the form close. This stopped the exception from happening, but I now get a scripting error.
This program loads a new browser in a new tab every time a link is clicked.
Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Try
Dim i As Integer
For i = tpgBrowsers.TabPages.Count - 1 To 0 Step -1
tpgBrowsers.TabPages.RemoveAt(i)
Next
Catch ex As Exception
End Try
End Sub
This function Gets rid of any popup windows
Private Sub NewWindow(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs)
Try
e.Cancel = True
Catch ex As Exception
End Try
End Sub
The next to subs handle any scripting exceptions that occur, it automatically set's them to handled, so no message box pops up
Private Sub Navigated(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatedEventArgs)
AddHandler CType(sender, Windows.Forms.WebBrowser).Document.Window.Error, AddressOf WindowError
End Sub
Private Sub WindowError(ByVal sender As Object, ByVal e As System.Windows.Forms.HtmlElementErrorEventArgs)
Try
e.Handled = True
Catch ex As Exception
End Try
End Sub
When I close the program, the page tries to load a popup, that handler still works. Then a scripting error occurs, and for some reason it isn't handled by WindowError. So, given I've opened up 15 sites during an instance of the program. When it's closed, I may get about 10 message boxes pop up in sequence after the program is closed.
I tried using dispose instead of remove in the formclosing function. When I dispose of the browsers, the pop up window gets through, and I get the scripting error.