Results 1 to 2 of 2

Thread: selecting a tab in a thread

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2011
    Posts
    184

    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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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
  •  



Click Here to Expand Forum to Full Width