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

Thread: STA error Exception.InnerException

  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
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,830

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center