Results 1 to 5 of 5

Thread: Cross-thread operation not valid: Control 'Panel1' accessed from....

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    14

    Cross-thread operation not valid: Control 'Panel1' accessed from....

    Hi,

    This is the error message I am getting:

    "Cross-thread operation not valid: Control 'Panel1' accessed from a thread other than the thread it was created on."


    Now I know there have been some topics similar to this but they didn't really help and most were confusing.

    The reason I am getting this error is because I am opening up a new form and then calling these three things:

    Panel1.Show()
    Label1.Show()
    Label2.Show()

    The only reason is I don't understand why I get this error message because it doesn't occur normally if I open Form2 after closing Form1, it only occurs when I open Form2 after closing Form4.

    Any help would be most appreciated
    Thanks

  2. #2
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Cross-thread operation not valid: Control 'Panel1' accessed from....

    The other topics are bound to explain the real reason why this is happening, possibly they are hard for you to grasp. Unfortunately this is something you are going to have to read up on at some point.

    We will not be able to given any specific advise as the context you are getting this in could be vastly different from what we would expect, hence you are getting an error.

    To get you going, the reason for your error is not the code you are running, it is where you are calling the code from (or on your behalf). When you get this error, look at the stack trace (if you have no idea what that is, you need to learn). You can put a break-point (another thing to learn) on this line and see what happens when it works correctly. Then you can look at it again when it breaks. The stack trace will tell you the steps taken to get to this code. You could post that info and we might have an idea of how to give you more specific advice.

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    14

    Re: Cross-thread operation not valid: Control 'Panel1' accessed from....

    I tried using some code to display the stack trace but that didn't work (unless there's a manual way to do it which I am unaware of) and using break points didn't really show me anything I didn't already know. I'm still getting used to VB so sorry if I may be frustrating you with ignorance!

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    14

    Re: Cross-thread operation not valid: Control 'Panel1' accessed from....

    Okay FYI I got it to work finally by following this:

    http://www.codeproject.com/KB/recipe...romThread.aspx

  5. #5
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Cross-thread operation not valid: Control 'Panel1' accessed from....

    Notice that the post mentioned jmc from this forum as the instigator .

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