|
-
Jul 20th, 2010, 02:39 PM
#1
UI Thread and Secondary thread interaction
With threading, the WebBrowser control behaves abnormally.
While other controls allow accessing properties and error out when trying to set it, the WebBrowser control behaves just the opposite. It allows to set the property and errors out when trying to access it.
Anyone knows the reason why?
Here's a small test:
Code:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim th As New Threading.Thread(AddressOf DoWork3)
th.IsBackground = True
th.Start()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim th As New Threading.Thread(AddressOf DoWork4)
th.IsBackground = True
th.Start()
End Sub
Private Sub DoWork3()
TextBox1.Text = "test" '<-- this errors out
WebBrowser1.DocumentText = "<html>test</html>" '<-- this works
End Sub
Private Sub DoWork4()
Dim txt = TextBox1.Text '<-- this works
Dim wbdoc = WebBrowser1.DocumentText '<-- this errors out
End Sub
Last edited by Pradeep1210; Jul 20th, 2010 at 02:44 PM.
-
Jul 20th, 2010, 06:55 PM
#2
Re: UI Thread and Secondary thread interaction
The simple fact is that you shouldn't be accessing any control properties at all on any thread other than the UI thread. Don't do it and it can never go wrong.
-
Jul 20th, 2010, 07:34 PM
#3
Re: UI Thread and Secondary thread interaction
Sometimes you can access controls outside of the controls they were created on and sometimes you can't. It's a little odd that way, but this is nothing more than a coincidence. It may work in this instance, but fail in another. It has nothing to do with the specific control.
Last edited by weirddemon; Jul 20th, 2010 at 07:39 PM.
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
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
|