Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

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)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.