CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Hybrid View

  1. #1
    Join Date
    Sep 2013
    Posts
    2

    STA error Exception.InnerException

    Hi,
    I need a little help on an InvalidoperationException was unhandled by user code.

    The error occurs when I call this Sub located in a Module from a Timer (System.Timers.Timer) also located in the Module.

    Thank you in advance.

    This is a Google translation of the error message from VB.NET
    An error occurred during the creation of the form. See Exception.InnerException for more information. The error was: User thread should be STA, because this is required for many UI components.

    Code:
        Public Sub SetSpeechActive(ByVal TurnOn As Boolean)
            If TurnOn Then
                frmMain.picSpeechActive.Image = System.Drawing.Image.FromFile(System.Windows.Forms.Application.StartupPath & "\images\online16.png")
            Else
                frmMain.picSpeechActive.Image = System.Drawing.Image.FromFile(System.Windows.Forms.Application.StartupPath & "\images\offline16.png")
            End If
        End Sub

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: STA error Exception.InnerException

    The error message would seem to indicate that you have launched a new thread where this code is running but you are trying to update the GUI and the thread doesn't support it
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Sep 2013
    Posts
    2

    Re: STA error Exception.InnerException

    Quote Originally Posted by DataMiser View Post
    The error message would seem to indicate that you have launched a new thread where this code is running but you are trying to update the GUI and the thread doesn't support it
    Yes you are right. How would I update the picturebox from this thread. I don't know much about threads.

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

Featured