1
\$\begingroup\$

I am using multithreading in my XNA application and run my update logic s in a update thread(witch is a worker thread) and rendring is being done by main thread, now the problem is updation is required there on keyboard event, and key Board handling can be done only in main thread.

Note that my application was single threaded and I have implemented threading, synchronization is being done by 'data partitioning', both the threads are working correctly, except my keyboard is not working..

if any one have any suggestion or example, please allow me to know.

thanx in advance.

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

Input in XNA is not thread-safe and must be handled on the main thread. Simple as that.

Move your input polling to the main thread.

This is the thread safety of the XNA Framework (info is from XNA 3.1, but is probably still applicable):

  • GraphicsDevice is somewhat thread-safe

    • Cannot render from more than one thread at a time
    • Can create resources and SetData while another thread renders
  • ContentManager is not thread-safe

    • Ok to have multiple instances, but only one per thread
  • Input is not threadable

    • Windows games must read input on the main game thread
  • Audio and networking are thread-safe

Source: "Understanding XNA Framework Performance" by Shawn Hargreaves (Slide 27)

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .