I have an application that uses a BackgroundWorker to play files from a list. After I press the Stop button, the file that is running will stop running but will not stop the next file in the list from playing.
The variables in the code are:
playCount – how many files I have run, numberOfLoops – how much loops I want to run, Loops mean all the files in my list box (listBoxFiles), and myClass.playCapture – what runs in the background.
while (playCount < numberOfLoops && bContinuePlay && ifContinue) //play the file
{
for (int i = 0; (i < listBoxFiles.Items.Count) && bContinuePlay && ifContinue; i++)
{
string path = (string)listBoxFiles.Items[i];
myClass = new myClass(path, playSpeed);
myClass.evePacketProgress += new myClass.dlgPacketProgress(
(progressCount) =>
{
myClass._fileSelectedIndex = i;
bgWoSingle.ReportProgress(progressCount, myClass);
});
if (selectedAdapter != null)
{
bContinuePlay = myClass.playCapture(selectedAdapter._packetDevice); //here the BackgroundWorker running
}
}
playCount++;
}
I believe you just need to use the CancelAsync Method