Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>you can try using timer queue : <a href="http://msdn.microsoft.com/en-us/library/ms687003%28VS.85%29.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms687003%28VS.85%29.aspx</a> its basically using kernel scheduler to call your function callback at specified interval, the caller is from different thread so it won't interrupt the main thread and make your application responsive, the thread is managed by Windows so you don't have to manage your own pooling thread, and its relative accurate.</p> <p>implementation example: `</p> <pre><code>//a singleton class that hold timer queue class TimerQueue { protected: HANDLE timerQueue; TimerQueue() { this-&gt;timerQueue = ::CreateTimerQueue(); } ~TimerQueue() { if(this-&gt;timerQueue) { ::DeleteTimerQueueEx(this-&gt;timerQueue,NULL); this-&gt;timerQueue = NULL; } } public: static HANDLE getHandle() { static TimerQueue timerQueueSingleton; return timerQueueSingleton.timerQueue; } } //timer base class class Timer { protected: HANDLE timer; virtual void timerProc() = 0; static void CALLBACK timerCallback(PVOID param,BOOLEAN timerOrWait) { Timer* self = (Timer*)param; self-&gt;timerProc(); } public: Timer(DWORD startTimeMs,DWORD periodTimeMs) { if(!::CreateTimerQueueTimer( &amp;this-&gt;timer, TimerQueue::getHandle(), (WAITORTIMERCALLBACK)&amp;this-&gt;timerCallback, this, startTimeMs, periodTimeMs, WT_EXECUTEDEFAULT) ) { this-&gt;timer = NULL; } } virtual ~Timer() { if(this-&gt;timer) { ::DeleteTimerQueueTimer(TimerQueue::getHandle(),&amp;this-&gt;timer,NULL); this-&gt;timer = NULL; } } } //derive and implement timerProc class MyTimer : public Timer { protected: virtual void timerProc() { if(process.isRunning()) { process.kill(); } } public: MyTimer(DWORD startTimeMs,DWORD periodTimeMs) : Timer(startTimeMs,periodTimeMs) {} } //usage: int main(int argc,char* argv[]) { MyTimer timer(0,100); //start immediately, at 10 Hz interval } </code></pre> <p>`</p> <p>disclaimer : i don't test or compile those codes, you should recheck it</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload