Re: Intermittent work in UI thread
Thank you Joseph, I used a timer and it works as expected.
Do you think its OK to stop the timer at the beginning of its handler
and start it again at the end to prevent multiple messages from being
posted? Something like:
CMyWnd::OnTimer(UINT_PTR nIDEvent)
{
if(nIDEvent == IDT_WATCHER)
{
KillTimer(IDT_WATCHER);
//Fetch and process records
SetTimer(60000, IDT_WATCHER, NULL);
}
}
I want the next event to be 1 min after the end of the last one. This is
important because connecting to the DB and fetching data may take more
than 1 min. (I assume this is not a problem since this is not the main
thread and I'm not showing any windows)
Thanks,
Pedro Ferreira
Joseph M. Newcomer wrote:
Use WM_TIMER. Every 60,000 ms you process a timer message that starts the process. If
the process is paused, you kill the timer; if it is started again, restart the timer:
UWM_START_WATCHING: SetTimer(60000, IDT_WATCHER, NULL);
UWM_STOP_WATCHING: KillTimer(IDT_WATCHER);
WM_TIMER: for IDT_WATCHER, do DB query processing, updates
Note that no aspect of this thread will touch any window.
IDT_WATCHER is some value you invent to designate the timer
joe
On Mon, 15 Oct 2007 19:43:10 +0100, Pedro Ferreira <none@none.com> wrote:
Hi,
I'm trying to create a UI thread to do constant background work, but I'm
having some design problems.
The thread needs to fetch records from a database. do some processing on
each record and, when there are no more records, sleep for 1 minute
before check the database again. The process will be controlled with
thread messages (to start, pause, query...).
My problem is where should I put the processing work. I need it to be
responsive between cycles, where the process waits for 1 minute, so I
can stop it in that period. My only idea is using OnIdle to do the work.
But then, how should I make it real idle when waiting for 1 minute?
Could anyone give some hints on what is the way to go?
Thanks
Pedro Ferreira
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm