Thread problem updating Windows Forms control in XNA C#

Posted by Luis on Game Development See other posts from Game Development or by Luis
Published on 2011-06-18T19:28:13Z Indexed on 2011/06/22 8:31 UTC
Read the original article Hit count: 322

Filed under:
|

I'm development a network card game, and for now i've two players connected but there is a problem with one of them, this one can't do anything on the game. Looks that screen was blocked. I'm think that is because a code i used before.

That code is:

if (InvokeRequired)
            {
                this.Invoke(new MethodInvoker(delegate
                {

                   ...

            }));
                return;
            }

The code above is surrounding code to changing Button values, make connection with server and create game window. Without this code a warning is shown.

InvalidOperationException was unhandled

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

© Game Development or respective owner

Related posts about c#

Related posts about windows-forms