|
-
Jan 31st, 2013, 06:58 PM
#1
Thread Starter
Addicted Member
Question about what happens when I navigate form1.webrowser1 from non UI thread
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim navthread1 As New System.Threading.Thread(AddressOf Module1.navigate)
navthread1.Start("www.yahoo.com")
System.Threading.Thread.Sleep(1)
End Sub
Public Delegate Sub navigatecallback(ByVal site As String)
Public Sub navigate(ByVal site As String)
Dim main As Form1 = CType(System.Windows.Forms.Application.OpenForms(0), Form1)
If main.WebBrowser1.InvokeRequired Then
main.WebBrowser1.Invoke(New navigatecallback(AddressOf navigate), site)
Else
main.WebBrowser1.Navigate(site)
End If
End Sub
When I step through it runs like there is no multithreading at all. module1.navigate does not even start until after the buttonclick event sub has ended. What is the difference between this code that i've posted and doing this?:
(other than this bottom code navigates the webbrowser BEFORE the button click sub has ended)
Am I doin something wrong with my navthread1 which prevents it from doing anything until after the button1 click sub has ended?
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
form1.webbrowser1.navigate("www.yahoo.com")
End Sub
-
Jan 31st, 2013, 07:44 PM
#2
Re: Question about what happens when I navigate form1.webrowser1 from non UI thread
WebBrowser navigation is asynchronous already (just the navigation, mind, before all the naysayers pitch in!) so effectively you're starting a thread and invoking a callback to the UI thread to start yet another thread to do the navigation. If navigating is all you want to do then none of it is taking place in the thread that you have here.
I said a long time ago that the way to handle checking that a website was loaded if the program was otherwise not dependent on it was to start a timer to check when the particular element of interest was available and either process it or raise an alert or event at that time and then stop.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Jan 31st, 2013, 08:51 PM
#3
Thread Starter
Addicted Member
Re: Question about what happens when I navigate form1.webrowser1 from non UI thread
 Originally Posted by dunfiddlin
I said a long time ago that the way to handle checking that a website was loaded if the program was otherwise not dependent on it was to start a timer to check when the particular element of interest was available and either process it or raise an alert or event at that time and then stop.
So how would I handle this:
I navigate to a website, the document is completed, but the macros are not completed? The document completed event says DOCUMENT COMPLETED! But there is no macro completed event... When the document is completed but macros are not completed the HTML elements are the same as when the document is completed and the macros are completed.
What needs to happen for me to get the navigation of the webbrowser off of the UI thread?
-
Jan 31st, 2013, 11:48 PM
#4
Re: Question about what happens when I navigate form1.webrowser1 from non UI thread
What macros?
And you can't really get it off the UI thread because it inherently is updating the UI... so it's going to be on the UI thread by its very nature.
-tg
-
Feb 1st, 2013, 11:38 AM
#5
Re: Question about what happens when I navigate form1.webrowser1 from non UI thread
You may want to look into the WebRequest. A WebBrowser control is intended to show a web page to the user, which is why it is inherently UI. If you don't care whether the user sees anything or not, then a WebBrowser may not be what you want to use.
My usual boring signature: Nothing
 
-
Feb 1st, 2013, 01:42 PM
#6
Thread Starter
Addicted Member
Re: Question about what happens when I navigate form1.webrowser1 from non UI thread
 Originally Posted by techgnome
What macros?
And you can't really get it off the UI thread because it inherently is updating the UI... so it's going to be on the UI thread by its very nature.
-tg
The webpage HTML included an object and the object created in the website's HTML runs a macro which logs into the server created by the object. The macro happens after the document completed event. so for it to work i'd have to have some sort of wait function on the document completed event that waits for a half second for the document's objects to run it's macros.
-
Feb 1st, 2013, 01:42 PM
#7
Thread Starter
Addicted Member
Re: Question about what happens when I navigate form1.webrowser1 from non UI thread
 Originally Posted by Shaggy Hiker
You may want to look into the WebRequest. A WebBrowser control is intended to show a web page to the user, which is why it is inherently UI. If you don't care whether the user sees anything or not, then a WebBrowser may not be what you want to use.
I will look into this now! Thanks for the ideas!
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
|