一 开启线程
//设置一个信号量,判断是否线程结束
[cpp]view plaincopy
HANDLEg_hTic2 = CreateEvent(NULL, TRUE, TRUE, NULL);
[cpp]view plaincopy
View::StartTick2(intnSeconds)
{
m_bStopTic2 = FALSE;
AfxBeginThread(Tic2,this);
}
[cpp]view plaincopy
UINTTic2(LPVOIDpTView)
{
CMyView *pView = (CMyView *)pTView;
ResetEvent(pView->g_hTic2);//重置为无信号
while(!pView->m_bStopTic2)
{
//间隔多少时间刷新
Sleep(g_nShanshuoPinlv);
if(!pView->m_bMoveCapitalStart){
pView->InvalidateChunk(pView->pContentChunk);
}
}
SetEvent(pView->g_hTic2);//有信号
return1;
}
二关闭线程
[cpp]view plaincopy
View::EndTic2()
{
m_bStopTic2 = TRUE;
WaitForSingleObject(g_hTic2, INFINITE);
}
在关闭程序时候,可以先关闭刷新线程
[cpp]view plaincopy
View::CloseApp()
{
EndTic2();
((CMainFrame *)AfxGetMainWnd())->OnClose();
exit(0);
}
版权声明:www.gudianxiaoshuo.com (古典小说网) 今日头条号: 古典古韵古典小说、讨厌编程
网友评论