读书人

写个定时器每到半夜12点自动删除一个T

发布时间: 2012-08-08 14:32:45 作者: rapoo

写个定时器每到午夜12点自动删除一个TXT文件
RT、具体应该怎么写?是不是还要用到后台线程?

[解决办法]
1,起来一个线程
1,1创建一个线程类可以用:class CHostThread : public CWinThread

1,2 ,app中让线程起来:
CHostThread*m_taskThread;
m_taskThread = new CHostThread(50);
m_taskThread->Run();

2, 编写线程中:Run() 函数
int CHostThread:
{
const int nSmallTimeCycle = 60000 * 1;//1分钟检查一次时钟
int nTimeOut = 0;
while ( true )
{

if ( nTimeOut >= nCheckTaskInterval )
{
nTimeOut = 0;
//1,判断时间当前时间是否为12:00,
//2,如果是就执行相关任务
//*****

}
nTimeOut += nSmallTimeCycle;
Sleep(nSmallTimeCycle);

}
return CWinThread::Run();

}

读书人网 >VC

热点推荐