Webbrowser crashing VB.NET

javalsu

New member
Joined
Jan 24, 2007
Messages
4
Programming Experience
1-3
I have a program that uses multiple webbrowsers that are created during run time. The webrowsers work just fine. However, whenever I try to close the program, it crashes.

After further inspection I found out that some of the sites that are accesses are trying to set the homepage to their URL using javascript. The crash is caused due to a permissions error. How can I avoid this?
 
you could put the exit code inside a try/catch block, this will prevent the application from crashing

in the catch section of the try/catch block is where you would force the page to close
 
No good

Thanks for the suggestion, but I've already tried that.

I believe what's causing the problem is occurring after the program exits. The clients side code that is called is still try to execute after the program closes. This is where the errors come in, because the browser it's trying to access doesn't exist anymore.
 
Update

I've found that if I dispose of the browsers during the closing, then the error doesn't happen. Instead a popup window comes up. This is a problem, because for some reason, it doesn't call the new_window event, and block the popup.

However, if I dispose of the tab, that contains the webbrowser control. Then a popup doesn't occur, but a scripting error does, which I'm trying to suppress.

Any ideas?
 
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.


 
Back
Top