I have the following code :
class SoundPlayback
{
protected volatile bool _playing;
public bool Playing {...}
protected void Begin()
{
while (Playing && _sheet.TimeTick != 0)
{
_sheet.PlaySounds();
Thread.Sleep(_sheet.TimeTick);
}
_playing = false;
}
}
I have a thread calling Begin() with thread start, which works fine for the first time around, but when _playing is false and I want to resume the playback, I’m unable to.
Help would be appreciated.
Threads (any threads, not just .Net):
Sleep: BAD
Block-on-Event: GOOD
Take a look at “Synchronization Essentials” in this most excellent tutorial:
And change your loop to:
1) Call some other function do to the “work”
2) rely on some global “done” variable (instead of exiting when “TimeTick != 0”!!!!!)