Re: Prevent program freeze
Look up multithreading. You need to throw the code that loads your stuff into it's own thread so it doesn't freeze your UI while it runs.
Re: Prevent program freeze
Re: Prevent program freeze
.. Code:
Public Class Browser
Public thread As System.Threading.Thread
Private Sub Browser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim thread As New System.Threading.Thread(AddressOf DoCode)
Do While WebBrowser1.ReadyState <> WebBrowserReadyState.Complete
thread.Start()
Loop
End Sub
Public Sub DoCode()
WebBrowser1.Navigate("http://www.runescape.com/game.ws")
End Sub
End Class
Now I looked up threading etc..
I tried the backgroundworker and threading and neither of them solved my problem..
So either I'm doing this wrong or it's something else x(
Re: Prevent program freeze
Code:
Dim MyThread As System.Threading.Thread
Dim frmTest As New Form
Dim Browser As New WebBrowser
Public Sub DoLaunch()
frmTest.Height = 778
frmTest.Width = 712
frmTest.Controls.Add(Browser)
Browser.Dock = DockStyle.Fill
Browser.ScrollBarsEnabled = False
Browser.Navigate("http://www.runescape.com/game.ws")
frmTest.Show()
End Sub
Private Sub btnPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlay.Click
MyThread = New System.Threading.Thread(AddressOf DoLaunch)
MyThread.Start()
End Sub
I figured that to launch my thread correctly I'd have to put all the code in 1 thread. So instead of using a premade form I started off fresh.
But now I get the following error and I can't make sense of the online solutions .. :s
error:Unable to get the window handle for the 'WebBrowser' control. Windowless ActiveX controls are not supported.
Re: Prevent program freeze
You don't need multi-threading, nor would it work in this situation.
All you need is to use the events correctly.
This is what you should do:
1. Navigate to the page of your interest.
2. Use the WebBrowser DocumentCompleted event to determine when the webpage has loaded fully and take whatever action you want to based on that.