0

I have developed a .net library for XInput using P/invoke, and am now getting ready to implement it into a gui (WPF).

I have had a look at the BackgroundWorker class, and have got it working as a test for 1 controller, but its a hack job and clearly it wouldn't be suitable for 2-4 controllers (this was mainly done to see what I needed to do with the gui).

So I'm asking some more of the experienced people here, on how to approach the threading in this app. Should I continue with the BackgroundWorker class or look at TPL in .net 4, or some other method?

The worker thread is required as there is no messaging system for XInput, only a polling system. The worker thread would check input roughly every 20ms or something like that (Thread.Sleep). I am also not sure if there should be only 1 worker thread for all controllers or 4 worker threads (there is a max controller limit of 4).

I'm a bit new to WPF and .NET in general, so any advice welcome :)

John Saunders
  • 160,644
  • 26
  • 247
  • 397
marco9999
  • 83
  • 8
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Jan 17 '13 at 18:17

1 Answers1

0

TPL looks like overkill to me. It looks like it is intended for getting processor intensive tasks to run in parallel on multiple processors.

Polling the controllers will not be overly processor intensive. I would say that the background worker is up to the job, and should be able to handle all the controllers. Poll each controller at the same time.

David Sykes
  • 48,469
  • 17
  • 71
  • 80