如何停止从文件读取? [英] How to stop reading from a file?

查看:88
本文介绍了如何停止从文件读取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码更新如下,现在我可以重新启动,但直到再次单击按钮后才能停止.

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();
	
}

}

推荐答案

您应将读取的内容放入工作线程中,并从GUI线程向该线程发出停止读取"状态的信号(即主线程)设置标志.
例如
You should put the reading stuff inside a worker thread and signal to such thread the ''stop reading'' condition from the GUI one (i.e. the main thread) setting a flag.
e.g.
// 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) { }
} 


现在DigiManus的问题就存在了.您现在有一个已经解释的问题.您尝试过的是什么?

给你一些线索.
1.实现按钮功能
2.使用Ftell/fseek函数进行恢复.
3.关闭功能以关闭文件.
Now DigiManus''s question comes to existance. You have a problem now which you have explained. What is that you have tried??

To give you some clues.
1. Implement the Button function
2. Use Ftell/fseek functions for resuming.
3. Close function to close the file.


这篇关于如何停止从文件读取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆