|
-
Apr 28th, 2011, 03:55 PM
#1
Thread Starter
Junior Member
Prevent program freeze
Whenever I open my custom browser
my program freezes untill the loading has finished.
Is this normal?
And if it is then how can I prevent my program from not allowing me to go back to the other form untill the loading has completed?
I'm using this url as a start up page for my custom browser;
http://www.runescape.com/game.ws
it links directly to a java-based game.
when the game loads it checks for updates etc ( java app )
so can I prevent my program from freezing or not ?
It looks as if my custom browser form keeps demanding focus ..
Not that I'm able to change it by clicking..
I can at most make my program create the msg:
Not responding..
if I click on the browser form while loading.
If I wait it loads in about 10-15 seconds.
-
Apr 28th, 2011, 04:05 PM
#2
Fanatic Member
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.
Where I'm from we only have one bit of advice for new comers: "If you hear banjos, turn and run".
VS 2008 .NetFW 2.0
-
Apr 28th, 2011, 04:17 PM
#3
Thread Starter
Junior Member
Re: Prevent program freeze
Okay will do thanks
-
Apr 29th, 2011, 01:34 PM
#4
Thread Starter
Junior Member
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(
-
Apr 29th, 2011, 08:03 PM
#5
Thread Starter
Junior Member
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.
-
Apr 29th, 2011, 09:23 PM
#6
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|