Hi, I'm trying to put some animation code (simple things like increasing frame counters for sprites, or changing X/Y co-ords) into a dispatcher timer which sits in its own thread. This is so that the main loop draws the sprites as per the refresh rate of the monitor, but the animations/movements are refreshed every 1/60th sec regardless, so sprites don't animate/move twice as fast if you change monitor refresh from 60hz to 120hz (stupid example).
workerAnimation = new BackgroundWorker
{
WorkerReportsProgress = false,
WorkerSupportsCancellation = true
};
workerAnimation.DoWork += animationTimerStart;
workerAnimation.RunWorkerAsync();
void animationTimerStart(object sender, DoWorkEventArgs e)
{
animationTimer = new DispatcherTimer();
animationTimer.Tick += new EventHandler(animateSprites);
animationTimer.Interval = new TimeSpan(0, 0, 0, 0, 60);
animationTimer.Start();
do { } while (true);
}
void animateSprites(object sender, EventArgs e)
{
sprite.frame++; // simple example
sprite.x++;
}
The worker thread is set up ok, and loops infinitely in the do-loop (there's nothing else for this thread to do except tick the dispatcher timer), but the animationTimer never seems to tick, i.e. the animateSprites() function is never called. The main thread is running fine.
What am I doing wrong?