Jump to content
  • Advertisement
Sign in to follow this  
Matthew Shockley

VB Freezing

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

If you intended to correct an error in the post then please contact us.

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 Sub

End Class

Share this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!