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
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.