Click here to Skip to main content
15,886,110 members
Articles / Programming Languages / Visual Basic
Tip/Trick

Web Browser Hangs/Freeze Issue VB.NET

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
30 Oct 2014CPOL 14.8K   290   3  
The tip is for those who getting application hang/freeze issue in web browser control.

Introduction

This tip is for solution of web browser control hangs/freeze application issue. This is useful to those who used web browser control for scraping or visiting dynamic link, etc.

Background

When scraping website for visiting multiple links dynamically in a little time or in milliseconds/seconds, sometimes scripts of that page need more time to load content and in between you try to visit another page that hangs/freezes your application and crashes it. Most common error is "Out of memory".

Using the Code

Code for Visiting URL/ Navigation
VB.NET
WebBrowser1.ScriptErrorsSuppressed = True
WebBrowser1.Url = New Uri(URL)
WebBrowser1.AllowNavigation = True 

Line 1: "ScriptErrorsSuppressed" hides all its dialog boxes that originate from the underlying ActiveX control & script errors.

Line 2: Will visit/navigate to given URL.

Line 3: Will allow URL to navigate if denied.

Create Web Browser Navigating Event
VB.NET
Private Sub webBrowser1_Navigating(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating
    If (e.Url.ToString().Contains("about:blank")) Then
        WebBrowser1.Stop()
        WebBrowser1.AllowNavigation = False
        Return
    End If
End Sub  

Will stop browser while navigating the same URL multiple times for loading scripts and deny navigation.

Create WebBrowser Navigated Event
VB.NET
Private Sub webBrowser1_Navigated(ByVal sender As Object, _
    ByVal e As WebBrowserNavigatedEventArgs) _
    Handles WebBrowser1.Navigated
    WebBrowser1.AllowNavigation = True
End Sub 

Will allow navigation.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Comments and Discussions

 
-- There are no messages in this forum --