• 14
• 12
• 9
• 10
• 9

# VB Freezing

This topic is 2811 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am trying to get a web page's text with VB.net, and I am having a few problems. Can someone please help me with this:

Public Class Main    Dim Loading As Boolean = False    Public Function LoadPage(ByVal url As String)        Browser.Navigate(url)        Loading = True        While Loading        End While        Return Browser.DocumentText    End Function    Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load        TextBox.Text = LoadPage("http://www.universestick.com/")    End Sub    Private Sub Browser_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles Browser.DocumentCompleted        Loading = False    End SubEnd Class

##### Share on other sites
What's the problem you're having?

From first look you While...Loop needs work as it currently sits in an endless loop.

Also TextBox isn't defined anywhere, nor is Browser - unless they're globals, in which case they shouldn't be referenced inside the class, but instead be object passed to the class.

##### Share on other sites
Here is what I am trying to do: When I call the LoadPage function, the WebBrowser(Browser) starts to load the page. When it is done loading, it returns the document text.

##### Share on other sites
I see what you're trying to do, I'm assuming as the title is VB Freezing that the application stops responding and you have to forcibly exit it?

I'm positive you'll find that the execution is sitting in that While...Loop.

Basically if the Browser.Navigate() command is asynchronous then what you want to do should work, however, if it's synchronous, which I believe it is then either it will sit at the line Browser.Navigate() until it completes, at which point you set Loading = True and nothing will set it to false (as the Browse_DocumentCompleted) will have already been called. Or it'll finish the command instantly then and sit in the loop waiting, because the Browser_DocumentCompleted sub is never called.

Have you put a breakpoint on Loading = False to see if it's ever called? Have you stepped through the code line by line to see when the Browser.Navigate line is returned?

Try putting a DoEvents in the While...Loop and see if that improves it.