I have an XNA application that is never calling Draw()
(and update()
never gets called once). It is multithreaded. In particular, it holds a collection of objects which each call their own draw function.
The draw function looks like this:
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);
foreach (Interaction<InteractionState> interaction in interactions){
interaction.display(spriteBatch); //this calls the SpriteBatch Draw function
}
spriteBatch.End();
Interactions are objects which are updated by a custom input device, which is running on a separate thread.
When I only have one or two of these interactions, things run fairly fast, but when I start putting 3 or more, the drawing stops. Since it works with two Interactions, I am convinced the problem is not a matter of something like redundant content load calls or a bug in calling spritebatch.begin/end twice.
My best guess is that right now, increasing my input sources has increased the computational load on that thread to the point where it never gets a chance to call Draw. How can I force the game to Draw and take precedence over that other thread? I have tried setting the rate
this.TargetElapsedTime = TimeSpan.FromSeconds(1.0f / 10.0f);
and no inactivity:
this.InactiveSleepTime = TimeSpan.Zero;
Both in Initialize()
, and neither has done the trick.
Edit: People seem to be confused (I probably didn't word it well), but, I am ONLY trying to draw in the main thread. I am NOT trying to do any drawing in the background thread. The main draw method is never being called.
Edit 2: I can also say that if I make my background thread sleep for 150ms at a time, then the system starts drawing. That's too low of a framerate for my purposes though.