|
-
Apr 25th, 2012, 10:27 AM
#1
Thread Starter
Addicted Member
selecting a tab in a thread
I'm getting this error when try do a simple task of selecting a tab in a thread. What does it mean and how do you solve it?
System.Threading.ThreadStateException: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made.
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
Dim Thread1 As New System.Threading.Thread(AddressOf test_tab)
Thread1.Start()
End Sub
Private Sub test_tab()
TabControl1.SelectedTab = TabPage2
End Sub
-
Apr 25th, 2012, 10:40 AM
#2
Re: selecting a tab in a thread
You can't access the UI from a secondary thread. That's it, that's all. If you need to access the UI you must do it on the UI thread. If you're executing on a secondary thread then you must marshal a method call to the UI thread. To learn how to do that, follow the CodeBank link in my signature and check out my thread on Accessing Controls From Worker Threads.
Tags for this Thread
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
|