Problem: The wav files plays, but GUI does not respond at all. The lbl_PhonoString.Text is not updated every loop. User cannot pause or cancel until all the files are played completely.
I know I have to use a seaparate thread to play the Wav file. I am not at all familiar with threading. Can someone suggest what I should do here?
My Code:
//====================================================
bool bPause = false, bCancel = false;
private void btn_DicStart_Click(object sender,EventArgs e)
{
PlayWave("StartProgram.WAV");
for(int i=0;i<10;i++)
{
lbl_PhonoString.Text=i.ToString();
PlayWave("NextSound.WAV");
PlayWave("Clue"+i.ToString()+".WAV");
//Check if user pressed pause/cancel
while(bPause);
if(bCancel)
break;
}
}
private void btn_Pause_Click(object sender,EventArgs e)
{
bPause=!bPause;
if(!bPause)
btn_Pause.Text ="PAUSE";
else
btn_Pause.Text ="CONTINUE";
}
private void btn_Cancel_Click(object sender,EventArgs e)
{
bCancel=true;
}
//Play the Wave File
private void PlayWave(string WaveFile)
{
System.Media.SoundPlayer myPlayer=new System.Media.SoundPlayer();
myPlayer.SoundLocation=WaveFile;
myPlayer.PlaySync();
}
//====================================================