本文介绍了如何停止从文件读取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
代码更新如下,现在我可以重新启动,但直到再次单击按钮后才能停止.
The Code is updated as below now I am able to restart but the not able to stop untill I Click button again.
void CDemoDlg::ReadFileTxt()
{
CFileException fileException;
if (readFile.Open(strFilePath, CFile::modeRead, &fileException))
{
while ((stopSong==true )&&readFile.ReadString(strLine)){}
}
}
void CDemoDlg::OnBnClickedSongPlay()
{
if(stopSong==true)
{
stopSong=false;
readFile.Close(); /*stops but resumes immediately so could not recognize that it actually stopped*/
}
else
{
stopSong=true;
OnLbnSelchangeListSongs();
}
}
推荐答案
// worker thread, the 'stop_reading' variable is set by the GUI thread on button click
if (readFile.Open(strFilePath, CFile::modeRead, &fileException))
{
while (readFile.ReadString(strLine) && stop_reading == false) { }
}
这篇关于如何停止从文件读取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!