C++坐昼協扮匂
作者 佚名技术
来源 程序设计
浏览
发布时间 2012-05-23
* * All I ask is that if you use LRTimer in your project you retain the * * copyright notice. If you have any comments and suggestions please email me * * max[at]remoteSOS[dot]com * * * * 2008-6-23 Modified by ZhangLiang * * * ****************************************************************************** */ #include "stdafx.h" #include "LRTimer.h" #ifndef _WIN32_WINNT #define _WIN32_WINNT 0x0500 #endif LRTimer::LRTimer(DWORD dwInterval): m_dwInterval(dwInterval), m_bRunning(FALSE), m_pCallback(NULL), m_pcbParam(NULL), m_hTimerThread(0) {} LRTimer::~LRTimer() {} VOID CALLBACK LRTimer::TimerAPCProc(LPVOID, DWORD, DWORD) { // call custom callback function if (NULL != m_pCallback) (*m_pCallback)(m_pcbParam); #ifdef _DEBUG else printf("No callback function set\n"); #endif } DWORD WINAPI LRTimer::timerThread() { HANDLE hTimer; BOOL bSuccess; LARGE_INTEGER liDueTime; CHAR szError[255]; CHAR szTimerName[16]; sprintf_s(szTimerName, "LRT_%x", (DWORD)(DWORD_PTR)this); if ( hTimer = CreateWaitableTimerA( NULL, FALSE, szTimerName ) ) liDueTime.QuadPart=-(LONGLONG)m_dwInterval * _SECOND; bSuccess = SetWaitableTimer( hTimer, // Handle to the timer object &liDueTime, // When timer will become signaled first time m_dwInterval, // Periodic timer interval TimerAPCProcAdapter, // Completion routine this, // Argument to the completion routine FALSE ); // Do not restore a suspended system if ( bSuccess ) { while (m_bRunning) SleepEx(1, TRUE); // SleepEx(0, TRUE) consumes 100% CPU usage CancelWaitableTimer(hTimer); } else { wsprintfA( szError, "SetW |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
关于C++坐昼協扮匂的所有评论