For the game I'm working on, I wanted to throw the audio into another stream so that I could queue the sounds and play immediately. The code that I use in this thread is as follows:
private void _checkForThingsToPlay() { while (true) { if (_song != null) { _playSong(_song); _song = null; } while (_effects.Count > 0) _playSfx(_effects.Dequeue()); Thread.Sleep(100); } }
This runs asynchronously and works great. However, without a call to sleep, it feeds on the entire processor core. My quest is sleep () - an effective way to reduce CPU usage, or are there any better ways to do this? My friend and I feel like this is a quick hack.
source share